开发者社区> 问答> 正文

使用nginx反向代理时,需要留意auth_basic是否也转给了后端

情况:nginx监听80端口,反向代理后边的tomcat,且nginx配置了auth_basic,凭密码访问。输入正确的用户名和密码,但nginx 总是提示错误。


过程:


1.查看nginx错误日志,有提示用户不存在的内容,如 user "liujia7" was not found in "D:\nginx-1.15.6/conf/passwd" ,但我明明输入的是用户名是 liujia


2.暂时移除nginx配置文件里的proxy_pass,再次测试,能正常验证密码


3.搜索网上资料,在nginx文件里恢复proxy_pass同时加上`proxy_set_header   Authorization "";` 即验证信息不转给后端的tomcat,最后测试,也能正常验证密码


location / {
            root   html;
            auth_basic "Restricted";
            auth_basic_user_file passwd;
            autoindex on;
            autoindex_exact_size on;
            autoindex_localtime on;
            proxy_pass http://tomcat_server$request_uri;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            #index  index.html index.htm;
            
            proxy_set_header   Authorization "";
        }




参考: https://serverfault.com/questions/511846/basic-auth-for-a-tomcat-app-jira-with-nginx-as-reverse-proxy

展开
收起
dongshan8 2018-12-27 10:55:20 3297 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
机器学习在互联网后端技术中的应用 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载