我有几个运行Atlassian Tomcat应用程序的子域名(jira.example.com,confluence.example.com,stash.example.com),我想知道是否可以使用.htpasswd
用basic_auth
对所有这些域进行密码保护。
Nginx的工作正常,没有basic_auth指令,但如果我尝试在nginx.conf
这样介绍它…
user nginx; worker_processes 1; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] $request ' '"$status" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; # Load config files from the /etc/nginx/conf.d directory include /etc/nginx/conf.d/*.conf; # Our self-signed cert ssl_certificate /etc/ssl/certs/fissl.crt; ssl_certificate_key /etc/ssl/private/fissl.key; # Password auth_basic "Restricted"; auth_basic_user_file /home/passwd/.htpasswd; # redirect non-ssl Confluence to ssl server { listen 80; server_name confluence.example.com; rewrite ^(.*) https://confluence.example.com$1 permanent; } # redirect non-ssl Jira to ssl server { listen 80; server_name jira.example.com; rewrite ^(.*) https://jira.example.com$1 permanent; } # # The Confluence server # server { listen 443; server_name confluence.example.com; ssl on; access_log /var/log/nginx/confluence.access.log main; error_log /var/log/nginx/confluence.error.log; location / { proxy_pass http://127.0.0.1:8080; proxy_set_header X-Forwarded-Proto https; proxy_set_header Host $http_host; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } # # The Jira server # server { listen 443; server_name jira.example.com; ssl on; access_log /var/log/nginx/jira.access.log main; error_log /var/log/nginx/jira.error.log; location / { proxy_pass http://127.0.0.1:9090/; proxy_set_header X-Forwarded-Proto https; proxy_set_header Host $http_host; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } }
..它要求凭据,但它然后返回一个
HTTP状态401 – 基本身份validation失败 – 原因:AUTHENTICATION_DENIED
http://oi43.tinypic.com/30l1c2u.jpg
看起来像有人设法解决这个与Apache运行作为反向代理http://jira.10933.n7.nabble.com/mod-proxy-and-password-protecting-td17279.html但该线程中的链接是死的.. 。
编辑:显然这个问题可以很容易地解决在Apache添加tomcatAuthentication="false"
并在Tomcat的server.xml连接器中使用protocol="AJP/1.3"
。 或者你可以阻止Apache转发的指令RequestHeader unset authorization
的authentication。 事情是,如何用Nginx做到这一点? 我想我必须研究更多..任何见解?
好的,只需在nginx邮件列表中find解决scheme。 我只是告诉nginx不要将auth头文件转发给tomcat。 在nginx.conf
的位置块中添加几行代码就可以实现:
location / { proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8090/; proxy_redirect off; # Password auth_basic "Restricted"; auth_basic_user_file /home/passwd/.htpasswd; # Don't forward auth to Tomcat proxy_set_header Authorization ""; }
现在我只需要弄清楚如何防止nginx在每个子域(jira,confluence,stash等)上请求auth。 不得不为所有人介绍这些证书是完美的,但这是另一个问题。
希望这可以帮助!
干杯。
我遇到了与Confluence相同的问题。 这是非常有用的(更新的问题和SDude的答案)。 我在每个子path级别上都有代理参数(“/ jira”,“/ wiki”用于Confluence等),所以我添加了proxy_set_header Authorization "";
到nginxconfiguration中的每个位置容器中修复问题。 它还解决了一个奇怪的问题,通过浏览器授权框而不是自己的login屏幕,Stash在Stash提示login密码。 以上它现在显示实际的login屏幕。
这个工作,直到你打击authentication的资源,通过触发一个popup的代理发回401头到客户端。
以下是来自https://answers.atlassian.com/questions/2515/answers/39133735?flashId=366096075
这是超级怪胎的老话题,但是对于这个问题来的任何人来说。 解决方法是在使用Apache2作为反向代理时取消授权标头。
RequestHeader unset Authorization
NGiNX也可以做到这一点
proxy_set_header Authorization "";
这很好,解决了这个问题。
但是,如果您的合stream安装允许匿名访问,并且与NGiNX / Apache2一起使用的身份validation与Confluence不同。 您将遇到特定元素的popup窗口。
例如,下面的链接“rest/我的工作/最新/状态/通知/新”
<status> <status-code>401</status-code> <message> Client must be authenticated to access this resource. </message> </status>