我已经配置了一些基本的身份验证来防止访问名为camera的目录,这是nginx服务器上我的站点启用目录中的代码:
location ^~ /camera/ {
auth_basic "Restricted Area";
auth_basic_user_file conf.d/htpasswd;
}
身份验证正在工作,如果用户名/密码错误,它将不会继续,但是现在发生了什么,它不是向用户显示受限制的页面,而是下载 PHP 文件,显然这不是我想要的,我怎么能停止它并显示页面?
谢谢
请阅读位置的工作原理:http://nginx.org/en/docs/http/ngx_http_core_module.html#location匹配后/camera/
位置nginx停止搜索任何其他位置。
如果最长匹配的前缀位置具有"^~"修饰符,则不检查正则表达式。
您需要在/camera/
内为进程.php文件添加嵌套位置。例如:
location ^~ /camera/ {
auth_basic "Restricted Area";
auth_basic_user_file conf.d/htpasswd;
location ~ '.php$ {
fastcgi_pass ...;
}
}