Nginx 中 jenkins-site.conf 部分的配置
location ^~ /jenkins/ {
proxy_pass http://localhost:8080;
sendfile off;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
// Be sure to set the X-Forwarded-Proto header if your reverse proxy is accessed via HTTPS and then Jenkins itself is accessed via HTTP i.e. proxying HTTPS to HTTP.
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect http:// https://;
}
解決 Windows JNLP slaves 無法通過 Nginx 連接 Jenkins 的問題
由於 Nginx 無法轉發 TCP 協議,故需要讓 Windows JNLP slaves 將請求直接發給Jenkins 的實際地址。具體步驟如下:
通過系統變量對 Jenkins 行爲進行更改,確保 hudson.TcpSlaveAgentListener.hostName 被設定爲 Jenkins (非 Nginx)所在的服務器地址;
export JENKINS_HOME=/data/jenkins-home/
nohup java \
-Dhudson.TcpSlaveAgentListener.hostName=192.168.1.110 \
-jar jenkins.war.jar --prefix=/jenkins > nohup.out 2>&1 &
設置完畢後,Jenkins 的所有頁面(及其發出/響應的 HTTP 請求)都會帶有額外的 HTTP header (X-Jenkins-CLI-Host) 包含上述信息,這些信息會給到 Windows JNLP slaves 去連接正確的 TcpSlaveAgentListener 的地址。