【代理】squid:http和https的代理服务器设置指南
2019年09月27日 11:00:03 作者:Jiaozn 分类:CICD 评论(0)我们曾经在介绍nginx的时候顺便使用nginx做过正向代理的设定,但是如果希望支持https的话,直接使用nginx则较为困难,而使用在这方面术业有专攻的squid则要简单的多。这篇文章用于记录在centos7上安装和设定squid3.5来实现http和https的步骤。
机器配置
[root@liumiaocn ~]# uname -a
Linux mail.163.com 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@liumiaocn ~]#
[root@liumiaocn ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@liumiaocn ~]#
安装squid
安装命令: yum install squid
确认版本
版本确认: rpm -qa |grep squid
[root@liumiaocn ~]# rpm -qa |grep squid
squid-migration-script-3.5.20-12.el7.x86_64
squid-3.5.20-12.el7.x86_64
[root@liumiaocn ~]#
确认ip_forward
ip_forward需要设定为1,缺省centos已设定,详细如下:
[root@liumiaocn ~]# sysctl -a |grep -w ip_forward
net.ipv4.ip_forward = 1
[root@liumiaocn ~]#
修改设定文件
修改前
[root@liumiaocn ~]# grep -n 'http_access deny all' /etc/squid/squid.conf
56:http_access deny all
[root@liumiaocn ~]#
修改后
[root@liumiaocn ~]# grep -n http /etc/squid/squid.conf |grep -w all
56:http_access allow all
[root@liumiaocn ~]#
启动squid
systemctl start squid
问题1:libssl错误
启动squid时提示如下错误
squid: relocation error: squid: symbol SSL_set_alpn_protos, version libssl.so.10 not defined in file libssl.so.10 with link time reference
原因:未安装openssl
对应方法: yum install openssl
安装之后启动squid即可:
[root@liumiaocn ~]# systemctl start squid
[root@liumiaocn ~]# systemctl status squid
● squid.service - Squid caching proxy
Loaded: loaded (/usr/lib/systemd/system/squid.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2018-06-05 20:07:56 CST; 8s ago
Process: 28548 ExecStart=/usr/sbin/squid $SQUID_OPTS -f $SQUID_CONF (code=exited, status=0/SUCCESS)
Process: 28540 ExecStartPre=/usr/libexec/squid/cache_swap.sh (code=exited, status=0/SUCCESS)
Main PID: 28551 (squid)
Memory: 14.3M
CGroup: /system.slice/squid.service
├─28551 /usr/sbin/squid -f /etc/squid/squid.conf
├─28553 (squid-1) -f /etc/squid/squid.conf
└─28557 (logfile-daemon) /var/log/squid/access.log
Jun 05 20:07:56 liumiaocn systemd[1]: Starting Squid caching proxy...
Jun 05 20:07:56 liumiaocn squid[28551]: Squid Parent: will start 1 kids
Jun 05 20:07:56 liumiaocn squid[28551]: Squid Parent: (squid-1) process 28553 started
Jun 05 20:07:56 liumiaocn systemd[1]: Started Squid caching proxy.
[root@liumiaocn ~]#
问题2:无法进行域名解析
此时发现无法使用域名只能使用ip来访问
原因:dns未配置,在squid的配置文件中添加8.8.8.8和8.8.4.4
[root@liumiaocn ~]# grep nameserver /etc/squid/squid.conf
dns_nameservers 8.8.8.8 8.8.4.4
[root@liumiaocn ~]#
[root@liumiaocn ~]# systemctl restart squid
[root@liumiaocn ~]#
客户端的访问
squid的缺省port为3128,在这里没有修改,在客户端使用如下方式即可访问:
http方式
export http_proxy=http://192.168.163.117:3128
curl http://www.baidu.com
https方式
export https_proxy=http://192.168.163.117:3128
curl https://www.baidu.com
评论
发表评论