5

I have intalled nginx on Windows and put an nginx.conf in my http root directory, but it seems this path is not included, I can include it by including c:/http_default/nginx.conf, but I want nginx to automaticaly include any nginx.conf for current working directory. Example: for http://mydomain.com/test/index.php, I want c:/http_default/test/nginx.conf to be included.

bisko
  • 3,948
  • 1
  • 27
  • 29
IVIR3zaM
  • 567
  • 9
  • 23
  • I don't understand why you would need to do this. Why not just make a location block for test that behaves differently? Another solution would be to have a different subdomain (then nginx could use a different virtual server to handle the test requests) – matzahboy Aug 16 '11 at 13:51
  • I'm working in ab big project, that it works with Apache. It have many .htaccess in its folders and cause it is a CMS and have plugins, each plugin may have its own .htaccess, I can translate .htaccess to nginx.conf but I need put every nginx to its folder. – IVIR3zaM Aug 16 '11 at 15:59
  • 1
    A .htaccess doesn't translate into a new nginx.conf. It translates to an nginx location block. Nginx allows you to include other configs based on certain locations (where it basically inserts the contents of the file), but it does not allow you to have more than 1 main config. – matzahboy Aug 16 '11 at 16:26
  • thank! when I change nginx.conf it need to restart, is any solution for when I change in nginx.conf it read it again without restart? – IVIR3zaM Aug 16 '11 at 16:56
  • 1
    I don't know the windows version of nginx (I use it on linux), but there's a 'reload' option on the nginx binary. That will reload the configuration on the fly. – matzahboy Aug 16 '11 at 17:31
  • how I can use this reload option in nginx.conf? can you show me an example line? (I wanna try it on linux) :D – IVIR3zaM Aug 22 '11 at 14:50
  • 1
    The 'reload' option is in the binary, not the nginx.conf file. I do the command 'sudo /usr/sbin/nginx -s start' to start nginx. To reload the config, I do 'sudo /usr/sbin/nginx -s reload' – matzahboy Aug 25 '11 at 02:53

2 Answers2

2

There is a program called incron, an "inotify cron" system. It detects file changes for a very low cost: inotify.

  • install incron, e.g. apt-get install -y incron

  • edit incrontab incrontab -e

  • add /var/www/site1/nginx.conf IN_MODIFY,IN_NO_LOOP /usr/local/sbin/nginx-reload.sh adjust your webroot, it is more secure to set webroot to sitename/server and put this nginx.conf in the username dir

  • the shell script uses flock to wait for the previous reload

    flock -x "/var/lock/nginx-reload" -c nginx-reload-worker.sh logger -t "nginx-reload[$$]" "Reloading OK"

  • the worker script delays every reload by 5 seconds

    sleep 5 service nginx reload || error 2 "nginx reload error"


See all this in NGINX auto reload gist

Szépe Viktor
  • 338
  • 2
  • 13
2

Your best option is to first have standardized directory structure (e.g. c:\www\example.com ). Then in each site directory have a directory for your root and for conf files. Then you'd use this in your main nginx.conf http { } section.

include c:/www/*/conf/nginx.conf;

Then each site's nginx.conf will get loaded when you start or issue a reload to nginx. So if you have these two paths for a site, you are set.

c:\www\example.com\conf\
c:\www\example.com\htdocs\

Web files go in htdocs and nginx.conf goes in conf. Simple as that.

I never used nginx on Windows, so I assume its' conf uses forward slashes like *nix.

SleighBoy
  • 501
  • 3
  • 12
  • This didn't work for me on Windows. I'm still trying to figure out how to do an include. – Ryan May 01 '14 at 17:17