首先有两台服务器A、B,其中A为局域网,B有公网。A配置(内网IP172.19.58.202\系统CentOS7.4),B配置(内网IP172.19.58.201\系统CentOS7.4)。现在A服务器是无法访问公网的,需要使用代理的方法让A通过有公网的B访问公网。 该操作一共可以分为两个部分:一、配置A代理 二、在服务器B上安装代理程序。 一、配置A代理#cd到/etc/profile.d/目录下 #新建proxy.sh,命名无所谓 [root@ali2 /] cd /etc/profile.d/ [root@ali2 profile.d] vi proxy.sh proxy.sh里面内容: #IP为要连接的代理服务器B,端口是要代理的端口,如下的意思该服务器要通过172.19.58.201服务器的端口10991的代理来访问公网 export http_proxy=http://172.19.58.201:10991 #如果要设置https代理,应该添加如下配置,暂未尝试过 #export https_proxy=http://172.19.58.201:10991 #设置不代理的IP或者网址,如下配置,这些请求不会被代理,不支持模糊匹配 export no_proxy="127.0.0.1, localhost, 172.19.58.202,172.19.58.201"
然后source /etc/profile,再使用指令echo $http_proxy,如果能打印出相关代理信息说明操作成功。 [root@ali2 profile.d] echo $http_proxy http://172.19.58.201:10991
二、在服务器B上安装代理程序#安装squid,这里采用yum的安装方式 [root@ali1 ~] yum install -y squid #cd到配置文件目录下 [root@ali1 ~] cd /etc/squid/ #备份原始配置文件 [root@ali1 ~] cp squid.conf squid.conf_bak #修改配置文件 [root@ali1 squid]# vi squid.conf
squid.conf配置文件修改内容如下
#将http_access deny all注释修改为http_access allow all #http_access deny all http_access allow all # 修改端口为代理的端口 http_port 10991 启动 #检查语法是否错误 [root@ali1 squid] squid -k parse #初始化缓存空间 [root@ali1 squid] squid -z [root@ali1 squid] 2018/12/05 13:58:56 kid1| Set Current Directory to /var/spool/squid 2018/12/05 13:58:56 kid1| Creating missing swap directories 2018/12/13:58:56 kid1| No cache_dir stores are configured. #启动squid [root@ali1 squid] service squid start Redirecting to /bin/systemctl start squid.service #检查端口是否开启成功 [root@ali1 squid]# netstat -an | grep 10991 tcp6 0 0 :::10991 :::* LISTEN
测试,使用wget baidu.com或curl www.baidu.com 测试内网服务器能否访问外网 [root@ali2 ~] wget baidu.com --2018-12-05 14:07:48-- http://baidu.com/ Connecting to 172.19.58.201:10991... connected. Proxy request sent, awaiting response... 200 OK Length: 81 [text/html] Saving to: ‘index.html.1’ 100%[=================================================================================================================================>] 81 --.-K/s in 0s 2018-12-05 14:07:48 (20.7 MB/s) - ‘index.html.1’ saved [81/81]
问题2:无法进行域名解析此时发现无法使用域名只能使用ip来访问
转自 (3条消息) 局域网服务器如何设置代理访问公网_y1006597541的博客-CSDN博客 (3条消息) squid:http和https的代理服务器设置指南_知行合一 止于至善-CSDN博客_squid 用squid做http/https正向代理 - 又是火星人 - 博客园 来源:https://www./content-4-864051.html |
|