名称定义
ProxyServer: 能上外网的服务器有2个IP,其中内网IP是192.168.0.10
Client: 不能上外网,希望通过ProxyServer进行更新的客户机,可以与ProxyServer连通。
配置ProxyServer
-
安装nginx(不在这里介绍)
-
增加一个
nginx
的子配置文件proxy_conf/proxys.conf
:
cd /usr/local/nginx/conf
sudo mkdir proxy_conf && cd proxy_conf
touch proxys.conf
- 用你喜欢的编辑器编辑
proxys.conf
server {
server_name localhost;
# ubuntu的代理
listen 9981;
location / {
proxy_pass http://mirrors.aliyun.com/ ;
}
# elasticsearch的代理
listen 9982;
location / {
proxy_pass https://artifacts.elastic.co/ ;
}
}
- 将proxys.conf的内容增加到nginx的配置中,打开
/usr/local/nginx/conf/nginx.conf
...
http
{
...
server
{
...
}
# 在此处增加刚才编辑的proxy配置
include proxy_conf/*.conf;
}
- 重启nginx,代理服务器设置完成。
配置Client
1. 配置ubunt apt的代理
(1) 打开/etc/apt/sources.list
(注意备份)。
(2) 查找文本内容http://archive.ubuntu.com
,替换为 http://192.168.0.10:9981
2. 配置elasticsearch的代理
(1) 打开/etc/apt/sources.list.d/elastic-7.x.list
(注意备份)。
(2) 查找文本内容http://artifacts.elastic.co
,替换为 http://192.168.0.10:9982
(3) 执行下面的命令添加elasticsearch的KEY
(参考[Install Elasticsearch with Debian Package | Elasticsearch Guide 8.0] | Elastic)
wget -qO - http://192.168.0.10:9982/GPG-KEY-elasticsearch | sudo apt-key add -
4. 更新
sudo apt update
参考链接: