脚本宝典收集整理的这篇文章主要介绍了php – 如何在nginx中的sublocations中全局使用FastCGI和Basic Auth?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
location ~ \.PHP { if (!-e $request_filename) { return 404; } include /etc/Nginx/fastcgi.conf; keepalive_timeout 0; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_SCRIPT_NAME; fastcgi_pass 127.0.0.1:9000; }
现在我想用基本的auth保护一些位置,如下所示:
location /madmin { auth_basic "Restricted"; auth_basic_user_file /VAR/www/localhost/admincp/.htpasswd; }
有了他的设置,Nginx在转到/ madmin时要求输入密码,但不会在/madmin/foo.PHP上询问.如果我将auth位置更改为“location~ ^ / madmin”,那么Nginx会提供PHP文件供下载…
是不是可以在Nginx中配置多个位置?如果没有,这里的解决方法是什么?
谢谢你的帮助.
如前所述,只有一个位置在Nginx中获胜;但是,您可能不知道Nginx支持位置内的位置.所以你的位置策略实际上可能就像这个示例服务器(0.8.31中的fastcgi.conf):
upstream my-backend { localhost:9000; } server { listen 80; server_name my-awesome-PHP.sITe; root /path/to/root; # The PRotected location location /protected { auth_basic "Give me codes."; auth_basic_user_file /path/to/.htpasswd; location ~ \.PHP${ include fastcgi.conf; fastcgi_pass my-backend; } } # Normal files (blank location is OK,just means serve From root) location / { } # PHP for normal stuff location ~ \.PHP${ include fastcgi.conf; fastcgi_pass my-backend; } }
以上是脚本宝典为你收集整理的php – 如何在nginx中的sublocations中全局使用FastCGI和Basic Auth?全部内容,希望文章能够帮你解决php – 如何在nginx中的sublocations中全局使用FastCGI和Basic Auth?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。