滴水恩情 发表于 2024-6-9 14:57:44

Linux内网服务器通过代理访问外网服务器

目次
一、情况先容
二、安装squid
三、设置代理
扩展一、JAVA应用通过代理访问外网
扩展二、通过nginx代理实现yum跳转
扩展三、代理harbor镜像方式访问

一、情况先容

192.168.7.131可以通外网
192.168.7.129不通外网
须要通过代理的方式实现192.168.7.129可以访问外网
二、安装squid

 1、在192.168.7.131主机(可以访问外网)利用yum安装squid
https://img-blog.csdnimg.cn/dbc6a4d7f27445479c4283fd28a8ea04.png
yum -y install squid   2、编辑/etc/squid/squid.conf设置文件
https://img-blog.csdnimg.cn/fb02f061e841455aaf86ad00cfe584f5.png

 默认端口为3128,可根据现实需求更改
 3、启动squid服务并实现开机自启
systemctl start squid

systemctl enable squid 三、设置代理

1、在不通外网的主机192.168.7.129举行测试curl www.baidu.com
https://img-blog.csdnimg.cn/417b04d9462c40eeaf057c92f87d1f75.png
2、在/etc/profile中添加以下内容
# tail -2 /etc/profile
export http_proxy=http://192.168.7.131:3128
export https_proxy=https://192.168.7.131:3128
# source /etc/profile 3、设置后再次测试
https://img-blog.csdnimg.cn/ff977899f1ea4e9caa33539c79a549f8.png
扩展一、JAVA应用通过代理访问外网

bin/setenv.sh文件中添加
-Dhttp.proxyHost=192.168.7.131 -Dhttp.proxyPort=3128 -Dhttps.proxyHost=192.168.7.131 -Dhttps.proxyPort=3128 扩展二、通过nginx代理实现yum跳转

1、在通外网的主机上设置nginx
#nginx配置文件中添加如下参数,暴露本机的8082 8083端口,将请求转发至mirrors.aliyun.com
# vim /etc/nginx/nginx.conf
    server {
      listen       192.168.7.131:8083;
      server_namemirrors.cloud.aliyuncs.com;

      location / {
          proxy_passhttp://mirrors.aliyun.com;
          # indexindex.html index.htm;
      }
      error_page   500 502 503 504/50x.html;
      location = /50x.html {
            root   html;
      }

}
    server {
      listen       192.168.7.131:8082;
      server_nameepel.com;

      location / {
          proxy_pass http://mirrors.aliyun.com;
          # indexindex.html index.htm;
      }
      error_page   500 502 503 504/50x.html;
      location = /50x.html {
            root   html;
      }

}
# systemctl start nginx 2、在不通外网主机/etc/yum.repos.d/目次下更换yum源
# cd /etc/yum.repos.d/
# ls
CentOS.repoepel-7.reporepo
# sed -i s/mirrors.aliyun.com/192.168.7.131:8083/g CentOS.repo
# sed -i s/mirrors.aliyun.com/192.168.7.131:8082/g epel-7.repo 3、测试:
# yum-y install squid https://img-blog.csdnimg.cn/f4bb2044adfe49108ca52cede80146d3.png
扩展三、代理harbor镜像方式访问

1、确保外网主机到镜像仓库网络可达
https://img-blog.csdnimg.cn/07c507cf0d604c94ba543239b96d70dd.png
 2、内网主机docker设置文件中添加如下参数
mkdir/etc/systemd/system/docker.service.d
vim /etc/systemd/system/docker.service.d/http-proxy.conf

Environment="HTTP_PROXY=http://192.168.7.131:3128"
Environment="HTTPS_PROXY=http://192.168.7.131:3128"
systemctl daemon-reload
systemctl restart docker 3、测试:
https://img-blog.csdnimg.cn/1a04186eed574d658888b80bf192dec0.png


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: Linux内网服务器通过代理访问外网服务器