nginx projects in subfolders

Posted by Timothy on Server Fault See other posts from Server Fault or by Timothy
Published on 2011-01-05T05:00:37Z Indexed on 2011/01/05 5:56 UTC
Read the original article Hit count: 315

Filed under:
|
|

I'm getting frustrated with my nginx configuration and so I'm asking for help in writing my config file to serve multiple projects from sub-directories in the same root. This isn't virtual hosting as they are all using the same host value. Perhaps an example will clarify my attempt:

  • request 192.168.1.1/ should serve index.php from /var/www/public/
  • request 192.168.1.1/wiki/ should serve index.php from /var/www/wiki/public/
  • request 192.168.1.1/blog/ should serve index.php from /var/www/blog/public/

These projects are using PHP and use fastcgi.

My current configuration is very minimal.

server {
    listen 80 default;
    server_name localhost;

    access_log /var/log/nginx/localhost.access.log;

    root /var/www;
    index index.php index.html;

    location ~ \.php$ {
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME /var/www$fastcgi_script_name;
        include fastcgi_params;
    }
}

I've tried various things with alias and rewrite but was not able to get things set correctly for fastcgi. It seems there should be a more eloquent way than writing location blocks and duplicating root, index, SCRIPT_FILENAME, etc.

Any pointers to get me headed in the right direction are appreciated.

© Server Fault or respective owner

Related posts about php

Related posts about nginx