使用nginx反向代理解决jenkins插件更新慢问题

本文参考链接https://my.oschina.net/VASKS/blog/3106314
具体原理及说明请参考原文。
由于本人纯新手因此详细记录操作过程,便于以后查阅。

系统环境如下:

操作系统:ubuntu 18.04
jenkins版本:2.222

修改hosts文件添加内容如下

127.0.2.1 updates.jenkins-ci.org
## Google为网络连通性测试地址,由于本人网络无法访问,因此也反向代理到百度
127.0.2.2 www.google.com

安装nginx

sudo apt-get install nginx

配置nginx反向代理

  • 新增配置文件 /etc/nginx/sites-enabled/updates.jenkins-ci.org.conf
    jenkins的default.json中要访问updates.jenkins-ci.org/download/xxxxx,把updates.jenkins-ci.org/download替换为mirrors.tuna.tsinghua.edu.cn/jenkins

使用 “location ^~ /download/” 来控制这个子页面的访问

内容如下:

server
{
    listen 80;
    server_name updates.jenkins-ci.org;
    location / {
        proxy_redirect off;
        proxy_pass https://mirrors.tuna.tsinghua.edu.cn/jenkins;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Accept-Encoding "";
        #proxy_set_header User-Agent "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.49 Safari/537.36";
        proxy_set_header Accept-Language "zh-CN";
    }
    location ^~ /download/
    {
        proxy_pass https://mirrors.tuna.tsinghua.edu.cn/jenkins/;
    }
    index index.html index.htm index.php;
    #error_page   404   /404.html;
    location ~ /\.
    {
        deny all;
    }
    access_log  /var/log/nginx/mirrors.access.log;
    error_log   /var/log/nginx/mirrors.error.log;
}
  • 新增配置文件 /etc/nginx/sites-enabled/google.com.conf
    内容如下:
server
{
    listen 80;
    server_name www.google.com;
    location / {
        proxy_redirect off;
        proxy_pass https://www.baidu.com/;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Accept-Encoding "";
        #proxy_set_header User-Agent "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.49 Safari/537.36";
        proxy_set_header Accept-Language "zh-CN";
    }
    index index.html index.htm index.php;
    #error_page   404   /404.html;
    location ~ /\.
    {
        deny all;
    }
    access_log  /var/log/nginx/google.access.log;
    error_log   /var/log/nginx/google.error.log;
}

然后重启nginx服务就可以了

service nginx restart
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值