How to configure nginx to read nginx.conf in the current working directory?

I enabled nginx on Windows and put nginx.conf in my http root directory, but it seems that this path is not included, I can enable it by turning on c:/http_default/nginx.conf , but I want nginx to automatically include any nginx.conf for the current working directory. Example: for http://mydomain.com/test/index.php , I want to include c:/http_default/test/nginx.conf .

+4
source share
2 answers

Your best bet is to first create a standardized directory structure (e.g. c: \ www \ example.com). Then in each directory of the site there is a directory for your root and for conf files. You will then use this in your main nginx.conf http {} section.

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

Then, each nginx.conf site will be loaded when starting or releasing a reboot for nginx. So, if you have these two paths for the site, you are set up.

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

Web files are in htdocs, and nginx.conf is in conf. Just like that.

I have never used nginx for Windows, so I assume that its "conf" uses slashes like * nix.

+2
source

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

  • install incron, for example. 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 set up your website, it is safer to install webroot in sitename / server and put this nginx.conf in the username dir

  • shell script uses flock to wait for previous reboot

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

  • working script delays every reboot for 5 seconds

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


See it all in NGINX auto reload gist

+2
source

All Articles