服务器1 不通外网,通过服务器2代理,访问外网
1. 在服务器2上安装 squid
1.1 安装 squid(博主是deepin系统)
javascript
sudo apt update
sudo apt install squid
检查是否安装成功:
javascript
squid -v
1.2 修改 squid 配置
备份原配置:
javascript
cd /etc/squid/
sudo cp squid.conf squid.conf_bak
编辑 配置文件,增加如下内容:
javascript
# 基本配置
http_port 3128
# 定义ACL规则 - 允许服务器1的IP访问
# 假设服务器1的内网IP是 192.168.1.100
acl server1 src xxxx具体ip/32
# 如果有多台服务器需要代理,可以配置网段
# acl internal_network src 192.168.1.0/24
# 定义安全端口
acl Safe_ports port 80 # http
acl Safe_ports port 443 # https
acl Safe_ports port 21 # ftp
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
# 访问控制规则
# 允许服务器1使用代理
http_access allow server1
# 允许本地访问
http_access allow localhost
http_access allow all
# 拒绝其他所有
#http_access deny all
# 缓存设置(可选)
cache_dir ufs /var/spool/squid 100 16 256
maximum_object_size 4 MB
# 日志设置
access_log /var/log/squid/access.log squid
cache_log /var/log/squid/cache.log
检查语法是否正确:
javascript
sudo squid -k parse
没有FATAL 提示就没问题,有提示 按照提示修改
1.3 启动 squid
javascript
sudo systemctl restart squid
1.4 查看端口
javascript
sudo netstat -tlnp | grep 3128
1.5 测试是否配置正确
javascript
curl -x http://xxx服务器1地址:3128 http://www.baidu.com
- 在服务器1上 配置代理
2.1 修改 /etc/profile
在末尾追加如下:
javascript
export http_proxy="http://服务器1地址:3128"
export https_proxy="http://服务器1地址:3128"
export ftp_proxy="http://服务器1地址:3128"
export no_proxy="localhost,127.0.0.1,192.168.1.0/24"
2.2 让配置生效
javascript
source /etc/profile
检查配置:
javascript
echo $http_proxy
如果打印:http://服务器1地址:3128
就OK了
2.3 测试是否配置成功
javascript
curl www.baidu.com