首页 > 其他 > 详细

为jenkins设置nginx作为反向代理

时间:2021-03-11 19:10:06      阅读:36      评论:0      收藏:0      [点我收藏+]

新版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

为jenkins设置nginx作为反向代理

原文:https://www.cnblogs.com/guohong-hu/p/14519809.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!