因为各种业务需求,需要用到代理服务器,来加快网路的访问速度,和一些内网的访问,下面就是如何搭建代理服务器。
操作步骤
-
yum 安装 squid 和httpd-tools (-y 全自动安装)
yum update -y
yum install squid -y
yum install httpd-tools -y
-
生成密码文件
mkdir /etc/squid3/
#username 是用户名
htpasswd -cd /etc/squid3/passwords username
#提示输入密码,输入即可 注意密码不要超过 8 位
#测试密码文件
/usr/lib64/squid/basic_ncsa_auth /etc/squid3/passwords
# 输入 用户名 密码
username password
# 提示 OK 说明成功,ERR 是有问题,请检查一下之前步骤
OK
# 测试完成,crtl + c 打断
-
配置squid.conf文件
vi /etc/squid/squid.conf
配置文件加入:
#ncsa_auth的路径要找到自己安装的地方。一般在/usr/lib/squid/或者/usr/lib/squid3/视版本而定。
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid3/passwords
acl ncsa_users proxy_auth REQUIRED
http_access allow ncsa_users
#把http_access allow localnet , http_access allos localhost屏蔽掉。
-
# 设置来源IP白名单,增加的这两行要在 http_access deny all 前面,因为squid配置文件是从上往下读的
acl localnet src 222.93.8.140
http_access allow client
# And finally deny all other access to this proxy
http_access deny all
#如果允许所有来源,请只需要添加以下:
http_access allow all
-
修改完配置文件后启动
# 先初始化一下
squid -z
# 启动
systemctl start squid.service
# 停止
systemctl stop squid.service
# 重启
#配置开机自启动
systemctl enable squid.service
如果发现还是无法启用,请按照以下方式排查解决:
-
默认端口被运营商屏蔽,更换端口即可
-
监听端口为 tcp6 :https://www.qkeke.com/archives/852.html