我们曾经在介绍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 ~]#
1
2
3
4
5
6
安装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 ~]#
1
2
3
4
确认ip_forward
ip_forward需要设定为1,缺省centos已设定,详细如下:
[root@liumiaocn ~]# sysctl -a |grep -w ip_forward
net.ipv4.ip_forward = 1
[root@liumiaocn ~]#
1
2
3
修改设定文件
修改前
[root@liumiaocn ~]# grep -n 'http_access deny all' /etc/squid/squid.conf
56:http_access deny all
[root@liumiaocn ~]#
1
2
3
修改后
[root@liumiaocn ~]# grep -n http /etc/squid/squid.conf |grep -w all
56:http_access allow all
[root@liumiaocn ~]#
1
2
3
启动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 ~]#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
问题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 ~]#
1
2
3
4
5
客户端的访问
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
点赞 2
————————————————
版权声明:本文为CSDN博主「liumiaocn」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/liumiaocn/article/details/80586879
推荐本站淘宝优惠价购买喜欢的宝贝:
本文链接:https://hqyman.cn/post/1119.html 非本站原创文章欢迎转载,原创文章需保留本站地址!
休息一下~~