我正在build立一个Jenkins服务器,在Apache后面的Tomcat下运行。 我使用的是使用SNI的SSL虚拟主机,因此我可以通过https://jenkins.example.com访问它,并在http://www.example.com上提供其他内容。
我已经启动并运行了,但是当我点击“pipe理Jenkins”时,它告诉我看来您的反向代理设置已经损坏 。
请注意,我正在使用自签名SSL证书,而jenkins.example.com不是默认的虚拟主机。
相关的apacheconfiguration如下所示:
<VirtualHost *:80> ServerName jenkins.example.com Redirect / https://jenkins.example.com/ </VirtualHost> <VirtualHost *:443> ServerName jenkins.example.com SSLEngine on SSLCertificateFile /etc/ssl/certs/jenkins.example.com.crt SSLCertificateKeyFile /etc/ssl/private/jenkins.example.com.key <Location /> AuthType Digest AuthName "Jenkins" AuthUserFile "/etc/htpasswords" Require valid-user </Location> ProxyRequests Off ProxyPreserveHost On <Proxy http://localhost:8080*> Order deny,allow Allow from all </Proxy> ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ ProxyPassReverse / https://jenkins.example.com </VirtualHost>
如果我做:
curl --user "username:password" --digest -k https://jenkins.example.com/administrativeMonitor/hudson.diagnosis.ReverseProxySetupMonitor/test -L
然后我看到输出:
<div/>
如果我运行wgetdebugging,那么我看到在某些时候wget得到一个指向http而不是https的指针,不知道为什么发生这种情况,或者它是相关的,但它确实redirect:
---response begin--- HTTP/1.1 302 Moved Temporarily Date: Tue, 17 Jan 2012 19:47:16 GMT Server: Apache-Coyote/1.1 Location: http://jenkins.example.com/administrativeMonitor/hudson.diagnosis.ReverseProxySetupMonitor/test-for-reverse-proxy-setup Content-Length: 0 Keep-Alive: timeout=15, max=99 Connection: Keep-Alive Content-Type: text/plain
我在Ubuntu 11.04,Apache 2.2.17,Tomcat 6.0.28,Jenkins 1.448上运行。
我看到你的configuration的一个问题是:
ProxyPassReverse / https://jenkins.example.com
应该:
ProxyPassReverse / https://jenkins.example.com/
似乎该服务发送http://
而不是https://
位置标头(可能是因为您的Apache的监听器连接在localhost监听器上未encryption),在这种情况下,您需要添加:
ProxyPassReverse / http://jenkins.example.com/
因此,目前可能发生的情况是,API调用失败,因为它在redirect的Location:
头中获取了一个http://
地址(在ProxyPassReverse
由于它不是http
,因此未能进行翻译)。
它将请求发送到该位置,并从<VirtualHost *:80>
获得另一个redirect响应。 他们的有效性检查器知道这是不正确的和错误的,而curl
跟随一个更多的redirect,并得到一个有效的答复。
为http://
添加上面的ProxyPassReverse
,如果我是正确的,这应该可以解决这个问题。
如果您使用Apache作为反向代理,它至less需要2.2.18,并设置AllowEncodedSlashes NoDecode
选项(早期版本的值只有On和Off,两者都是错误的)。 以及ProxyPass
指令中的nocanon
。
两者都需要在VirtualHost中设置,因为AllowEncodedSlashes不被inheritance。
<VirtualHost *:80> AllowEncodedSlashes NoDecode ServerName build.example.org ProxyPass / http://localhost:8080/ nocanon ProxyPassReverse / http://localhost:8080/ ProxyRequests Off </VirtualHost>
通过https://stackoverflow.com/a/33179008/923560 :
确保系统configuration中configuration的Jenkins URL与您用于访问Jenkins的URL匹配。
要进入系统configuration:
确保端口值与位于机器Jenkins文件夹中的jenkins.xml文件的<arguments>
部分中设置的端口值匹配。