本文参考链接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