0
点赞
收藏
分享

微信扫一扫

Nginx auth_basic 403 Forbidden

fbd4ffd0717b 2022-11-05 阅读 108


一个PHP项目附带加了一个文档二级目录

密码输入是对的,可是不能访问

查看权限,也给这个目录访问权限了

# 出现403 Forbidden
https://www.demo.com/doc


# 测试发现,这个地址可以访问
https://www.demo.com/doc/index.html

nginx 部分配置如下

server {
listen 80;

server_name www.demo.com;
root /data/wwwroot/www.demo.com/public;

index index.php;

# 文档地址
location ^~ /doc {
# 设置 auth
auth_basic "login auth";
auth_basic_user_file /usr/local/nginx/.htpasswd;

alias "/data/wwwroot/doc.demo.com";
try_files $uri $uri/ /doc/index.html;
}

}

原因是没有加​​index.html​

应该写成这样

index  index.php index.html;

完整配置

server {
listen 80;

server_name www.demo.com;
root /data/wwwroot/www.demo.com/public;

index index.php index.html;

# 文档地址
location ^~ /doc {
# 设置 auth
auth_basic "login auth";
auth_basic_user_file /usr/local/nginx/.htpasswd;

alias "/data/wwwroot/doc.demo.com";
try_files $uri $uri/ /doc/index.html;
}

}

参考
​​​访问Nginx时出现‘’403Forbidden‘’的原因​​


举报

相关推荐

0 条评论