Nginx 反向代理 Jenkins 的配置方法

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 的地址。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章