为jenkins设置nginx作为反向代理
新版Jenkins不配置反向代理,直接用ip加端口访问会出现保存不了等错误。
新版增加了CSRF校验,需要关闭nginx的忽略无效header。在nginx.conf 的http模块添加或修改:
ignore_invalid_headers off;
在nginx的conf.d目录新增 jenkins.conf
upstream jenkins { server 127.0.0.1:8090; } server { listen 80; server_name jenkins-dev.com; charset utf-8; client_body_buffer_size 10M; proxy_redirect off; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Host $host:$server_port; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_next_upstream error timeout invalid_header http_502 http_503 http_504; proxy_ignore_client_abort on; proxy_read_timeout 180; proxy_buffering on; proxy_buffer_size 8k; proxy_buffers 8 8M; gzip on; gzip_min_length 1000; gzip_types text/plain text/css application/json text/xml application/xml application/xml+rss text/javascript; location / { proxy_pass http://jenkins; proxy_redirect default; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Host $host:$server_port; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
参考文档:
1. Jenkins官方文档,关于反向代理的说明,不配置或者反向代理配置错误都可能在管理页面有错误信息展示
https://www.jenkins.io/doc/book/system-administration/reverse-proxy-configuration-troubleshooting/
2. 为Jenkins配置nginx作为反向代理。
https://blog.csdn.net/weixin_34133829/article/details/93173932
3. nginx自定义header配置
https://www.cnblogs.com/ajianbeyourself/p/4104449.html