开发者

How to config nginx to read nginx.conf in current working directory?

开发者 https://www.devze.com 2023-03-28 13:19 出处:网络
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 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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号