我們?cè)?jīng)在介紹nginx的時(shí)候順便使用nginx做過(guò)正向代理的設(shè)定,但是如果希望支持https的話,直接使用nginx則較為困難,而使用在這方面術(shù)業(yè)有專攻的squid則要簡(jiǎn)單的多。這篇文章用于記錄在centos7上安裝和設(shè)定squid3.5來(lái)實(shí)現(xiàn)http和https的步驟。
成都創(chuàng)新互聯(lián)公司主要從事成都做網(wǎng)站、網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)太倉(cāng),十多年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來(lái)電咨詢建站服務(wù):18980820575
機(jī)器配置
[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
確認(rèn)版本
版本確認(rèn): 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 ~]#
確認(rèn)ip_forward
ip_forward需要設(shè)定為1,缺省centos已設(shè)定,詳細(xì)如下:
[root@liumiaocn ~]# sysctl -a |grep -w ip_forward net.ipv4.ip_forward = 1 [root@liumiaocn ~]#
修改設(shè)定文件
修改前
[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 ~]#
啟動(dòng)squid
systemctl start squid
問(wèn)題1:libssl錯(cuò)誤
啟動(dòng)squid時(shí)提示如下錯(cuò)誤
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
對(duì)應(yīng)方法: yum install openssl
安裝之后啟動(dòng)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 ~]#
問(wèn)題2:無(wú)法進(jìn)行域名解析
此時(shí)發(fā)現(xiàn)無(wú)法使用域名只能使用ip來(lái)訪問(wèn)
原因: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 ~]#
客戶端的訪問(wèn)
squid的缺省port為3128,在這里沒(méi)有修改,在客戶端使用如下方式即可訪問(wèn):
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
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)創(chuàng)新互聯(lián)的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接