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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值