Relative document root to configuration file

Kornél Schadl neil at
Mon Jun 13 04:52:17 MSD 2011

I've had to following problem:

I'm using svn/git for web based projects, and all projects contain an
nginx.conf with specific configurations for the virtualhosts it
contains. After updating code on the production server, all projects
are located in different directories:
project1 is in /var/www/project1, project2 is in /var/www/project2, etc.

In the main nginx configuration file (let's say
/usr/local/nginx/conf/nginx.conf) I include /var/www/*/nginx.conf. In
the virtualhosts' configuration file I specify document roots:
project1's conf file has a line "root /var/www/project1/web;",
project2's has a line "root /var/www/project2/web;".

On the development machine I work with, projects are on different
locations (/home/krnl/projects/project1, /home/krnl/projects/project2,
etc). Because of the root directive I have to share different copies
of the projects' nginx.conf file on the production server and a
different copy on my development host).

I created a patch, where if the root directive of a virtualhost starts
with '.' it finds the full path of the document root relative to the
configuration file's location (and not relative to the main
configuration file's location), so I can have the same version of
projects' nginx.conf on both hosts: "root ./web";

Until this I had: "root /var/www/project1/web;" on production server
and "root /home/krnl/projects/project1/web;" on development host. Now
I have "root ./web;" on both.

I tested it on linux and osx. Can I contribute the patch? If so, how
should I do this?


More information about the nginx-devel mailing list