Big*_*gie 9 php authentication nginx
我想用auth_basic用密码保护我网站的文件夹.此文件夹包含php脚本,如果请求它们应该执行.
我尝试了以下方法:
location /admin {
auth_basic "Admin-Section";
auth_basic_user_file /myfolder/.htpasswd;
}
location ~ ^/admin/.*\.php$ {
auth_basic "Admin-Section";
auth_basic_user_file /myfolder/.htpasswd;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Run Code Online (Sandbox Code Playgroud)
在请求该admin文件夹中的php脚本时,我将被要求输入用户名/密码,但是php脚本将始终被下载而不是通过fastcgi执行.
我究竟做错了什么?
编辑:在我的本地机器上一切正常,使用此配置.o0
编辑:BTW,php正在admin-folder之外使用相同的fastcgi-options.
编辑:天啊!该站点的配置存储在/ etc/nginx/sites-available/mysite和/ etc/nginx/sites-enabled /包含mysite文件的符号链接.因为有些时候改变mysite文件没有效果.例如,将所有位置更改为"全部拒绝"都没有效果.文件发送没有问题.
所以我删除了符号链接并重新启动了服务器.然后我再次创建了符号链接,重新启动了服务器,一切都按预期工作.有人可以解释奇怪的行为吗?
Gest问候,
Biggie
fis*_*est 12
有了这个配置,nginx的将只匹配一个两个块-一个具有最高优先级.
解决方案是将PHP块组合到 AUTH块中.这是nginx作者自己推荐的方法,Igor Sysoev.
location /admin/ {
auth_basic "Admin-Section";
auth_basic_user_file /myfolder/.htpasswd;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Run Code Online (Sandbox Code Playgroud)
小智 -1
您需要删除以下行:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12711 次 |
| 最近记录: |