宝塔反代加密访问
宝塔开启反向代理时,如果再开启目录加密访问,会优先目录加密访问,反向代理失效。
为解决这个问题,我们引入ngx_http_auth_basic_module
功能。
# 创建存储访问用户名和密码的目录
mkdir /www/wwwroot/protection_file
# 创建密码文件
touch /www/wwwroot/protection_file/htpasswd
# 设置密码
printf "user:$(openssl passwd -crypt password)\n" >>/www/wwwroot/protection_file/htpasswd
# 更新反向代理的配置文件(非网站配置文件)
# 避免重复配置文件内容,如原有配置文件已有代码部分,可删除。
#訪問限制
location /需要代理的目录 {
#頁面提示信息
auth_basic "保护目录";
#密碼文件路徑
auth_basic_user_file /www/wwwroot/protection_file/htpasswd;
#反向代理連接
proxy_pass http://原有代理地址;
}
#訪問限制END
参考链接:
https://www.skynicecity.com/rj/fixrptoproteced.html
https://cloud.tencent.com/developer/article/1157921