使用squid搭建http和https的代理服务器设置指南
我们曾经在介绍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
https方式
export https_proxy=http://192.168.163.117:3128
curl
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接