关于在VPS部署squid https通道的终极教程(已经彻底解决SSL编译的问题)

1,341 views
Skip to first unread message

Gary12

unread,
Feb 7, 2016, 8:06:58 AM2/7/16
to fq...@googlegroups.com
关于在VPS部署squid https通道的终极教程(已经彻底解决SSL编译的问题)

这里以squid4.0.4为例,平台是centos 7:

1. 编译:

wget http://www.squid-cache.org/Versions/v4/squid-4.0.4-20160205-r14526.tar.gz

tar -xvzf squid-4.0.4-20160205-r14526.tar.gz

cd squid-4.0.4-20160205-r14526

编译之前做好基础准备,安装好openssl 和gcc等,这里就不废话了.

下面是编译的重中之重,直接决定了squid是否能真正支持SSL, 这也是我摸索了好久,今天终于摸索出来突破的成果:

./configure  '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-strict-error-checking' '--exec_prefix=/usr' '--libexecdir=/usr/lib64/squid' '--localstatedir=/var' '--datadir=/usr/share/squid' '--sysconfdir=/etc/squid' '--with-logdir=$(localstatedir)/log/squid' '--with-pidfile=$(localstatedir)/run/squid.pid' '--disable-dependency-tracking' '--enable-eui' '--enable-follow-x-forwarded-for' '--enable-auth' '--enable-auth-basic=DB,NCSA,NIS,POP3,RADIUS,SMB,getpwnam'  '--enable-auth-digest=file' '--enable-auth-negotiate=kerberos'  '--enable-cache-digests' '--enable-cachemgr-hostname=localhost' '--enable-delay-pools' '--enable-epoll' '--enable-icap-client' '--enable-ident-lookups' '--enable-linux-netfilter' '--enable-removal-policies=heap,lru' '--enable-snmp' '--enable-ssl' '--enable-ssl-crtd' '--enable-storeio=aufs,diskd,ufs' '--enable-wccpv2' '--enable-esi'   '--with-aio' '--with-default-user=squid' '--with-filedescriptors=16384' '--with-dl' '--with-openssl'

预配置完成以后,开始编译

make

等待15-20分钟

完成:

make install &&
cp src/auth/basic/NCSA/basic_ncsa_auth /usr/bin/

这里
basic_ncsa_auth是实现用户认证的关键文件,后面再讲,先把squid的https通道跑通再说。


然后运行:

squid -v
Squid Cache: Version 4.0.4-20160205-r14526
Service Name: squid
configure options:  '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-strict-error-checking' '--exec_prefix=/usr' '--libexecdir=/usr/lib64/squid' '--localstatedir=/var' '--datadir=/usr/share/squid' '--sysconfdir=/etc/squid' '--with-logdir=$(localstatedir)/log/squid' '--with-pidfile=$(localstatedir)/run/squid.pid' '--disable-dependency-tracking' '--enable-eui' '--enable-follow-x-forwarded-for' '--enable-auth' '--enable-auth-basic=DB,NCSA,NIS,POP3,RADIUS,SMB,getpwnam' '--enable-auth-digest=file' '--enable-auth-negotiate=kerberos' '--enable-cache-digests' '--enable-cachemgr-hostname=localhost' '--enable-delay-pools' '--enable-epoll' '--enable-icap-client' '--enable-ident-lookups' '--enable-linux-netfilter' '--enable-removal-policies=heap,lru' '--enable-snmp' '--enable-ssl' '--enable-ssl-crtd' '--enable-storeio=aufs,diskd,ufs' '--enable-wccpv2' '--enable-esi' '--with-aio' '--with-default-user=squid' '--with-filedescriptors=16384' '--with-dl' '--with-openssl' 'build_alias=x86_64-redhat-linux-gnu' 'host_alias=x86_64-redhat-linux-gnu'


你会发现
squid确实是4.0.4了。


2. 制作证书:

cd /etc/squid/

openssl req -new -x509 -days 7777 -nodes -out vps.pem -keyout vps.pem
openssl gendh 2048 >> vps.pem
openssl x509 -subject -dates -fingerprint -in vps.pem


3. 配置 squid.conf

vi /etc/squid/squid.conf


主要做以下修改(暂时不开启用户认证):


#http_access deny all
http_access allow all

# Squid normally listens to port 3128
#http_port 127.0.0.1:3128
https_port 443 cert=/etc/squid/vps.pem key=/etc/squid/vps.pem 


然后ESC :wq 存盘。


启动squid



[root@vultr ~]# squid


查看后台进程:


[root@vultr ~]# ps -ef |grep squid
root     21537     1  0 12:02 ?        00:00:00 squid
squid    21539 21537  0 12:02 ?        00:00:01 (squid-1)
squid    21540 21539  0 12:02 ?        00:00:00 (logfile-daemon) /var/log/squid/access.log
root     22642 22621  0 12:40 pts/3    00:00:00 grep --color=auto squid


到此为止:服务端基本配置完毕。


4. 客户端配置:


客户端配置远远没有你们想象中那么简单,因为自签发的证书是通过不了chrome的CA认证的!

所以,简单的建立一个https: vpsip:443的代理,chrome是无法识别,拒绝连接的!

怎么办? 所以这里需要引入stunnel, 通过stunnel跟VPS的SSL证书握手,因为stunnel不检查CA证书,所以没有这个问题,然后把外部的https连接转换为普通的本地http代理,这样chrome就不会检查证书了,因为普通的http连接是不需要检查证书的。 下面是详细的步骤:


a. 通过winscp把上面的vps.pem证书传回本地:

b. 下载安装stunnle (https://www.stunnel.org/downloads.html)

安装以后,主要不要签发生成stunnel自带的证书:

然后把vps.pem放入stunnel的config目录,然后编辑stunnel.conf文件:

把里面的内容统统删光,把下面的内容粘贴进去:


[https]
client = yes
accept  = 800
connect = VPS IP:443
cert = .\vps.pem


把你的VPS IP粘贴进去,800是本地代理监听端口,可以随便改。

启动stunnel


然后chrome通过swithyomega,新建一个http: 127.0.0.1:800的代理.


切换到此代理,OK! 搞定!现在已经可以用了! 至此squid的https通道已经完全搭建好了!


5. 实现squid用户认证:


因为你可能不希望什么人都可以随意的连接到你的VPS,需要更严格更安全的认证,这时候需要引入squid用户认证。


前面的编译的时候已经做了铺垫,编译生成了用户认证的关键文件: basic_ncsa_auth


下面还需要生成一个密码文件:

yum install httpd

htpasswd  /etc/squid/passwd user1
user1就是用户名
然后输入密码

New password:
Re-type new password:
记住此密码,密码文件存放在
/etc/squid/passwd
最后配置squid.conf文件

vi /etc/squid/squid.conf


主要做以下修改:


# And finally deny all other access to this proxy


auth_param basic program /usr/bin/basic_ncsa_auth /etc/squid/passwd
auth_param basic children 5
auth_param basic credentialsttl 2 hours
auth_param basic realm Example.com's Squid proxy-caching
acl auth_users proxy_auth REQUIRED
http_access allow auth_users


#http_access deny all
#http_access allow all

# Squid normally listens to port 3128
#http_port 127.0.0.1:3128
https_port 443 cert=/etc/squid/vps.pem key=/etc/squid/vps.pem 


完成以后


运行: ps -ef | grep squid


终止掉squid的进程


 ps -ef |grep squid


root     21537     1  0 12:02 ?        00:00:00 squid
squid    21539 21537  0 12:02 ?        00:00:01 (squid-1)
squid    21540 21539  0 12:02 ?        00:00:00 (logfile-daemon) /var/log/squid/access.log
root     22642 22621  0 12:40 pts/3    00:00:00 grep --color=auto squid


这里运行两次kill 21539


然后重启squid


[root@vultr ~]# squid

看看后台进程:


ps -ef |grep squid

root     21537     1  0 12:02 ?        00:00:00 squid
squid    21539 21537  0 12:02 ?        00:00:02 (squid-1)
squid    21540 21539  0 12:02 ?        00:00:00 (logfile-daemon) /var/log/squid/access.log
squid    21555 21539  0 12:03 ?        00:00:00 (basic_ncsa_auth) /etc/squid/passwd
root     23148 23132  0 13:00 pts/0    00:00:00 grep --color=auto squid


这里已经多了basic_ncsa_auth的用户认证进程,说明squidd的用户认证功能已经成功实现!


至此教程全部完成! 这里面最难的其实还是自编译squid SSL支持的实现,这也是我今天的一大突破!



2333

unread,
Feb 7, 2016, 10:41:59 AM2/7/16
to 翻墙论坛
请问下,1.如果购买或者申请个免费SSL证书,就可以免去配置stunnel吗,2.其它linux发行版能实现吗,谢谢。


Gary12

unread,
Feb 7, 2016, 11:01:18 AM2/7/16
to 翻墙论坛
1. 将自己签发的证书交给CA机构签名,可以免去配置stunnel
2. 我目前仅在centos上实验成功,红帽系的理论上应该都可以,比如ferora之类的。 debian系的ubuntu我还在实验,没有完全成功。


在 2016年2月7日星期日 UTC+8下午11:41:59,2333写道:

2333

unread,
Feb 8, 2016, 6:11:47 AM2/8/16
to 翻墙论坛
谢谢,新春快乐


真心猪猪

unread,
Feb 9, 2016, 12:17:21 PM2/9/16
to 翻墙论坛
问个问题,能不能像 goagent 一样,导入 squid 生成的 vps.pem 证书到系统根证书机构,然后免去配置stunnel吗?
Message has been deleted

Gary12

unread,
Feb 9, 2016, 11:56:48 PM2/9/16
to 翻墙论坛
试过了,不行,对于https的连接类型,即便导入证书也没用,必须导入有CA签名的证书才行。
我不知道letsencrypt免费证书是否可以,理论上应该可以,但是我不大会用。

在 2016年2月10日星期三 UTC+8上午1:17:21,真心猪猪写道:

真心猪猪

unread,
Feb 10, 2016, 4:23:58 AM2/10/16
to 翻墙论坛
看来 https 代理的证书验证有点严格啊,正规的CA证书,价格不菲啊,我也在想,应该可以用 letsencrypt 的免费证书,现在的主流浏览器都已经信任 letsencrypt 的免费证书了,就是对 letsencrypt 的免费证书操作不太了解,好像挺复杂的,好像要用 letsencrypt 自己的 CA 管理工具操作。

不晓得有没有大神详细研究过 letsencrypt 的免费证书

Gary12

unread,
Feb 11, 2016, 8:40:02 AM2/11/16
to fq...@googlegroups.com
各位道友, 今天是我在squid SSL编译取得大圆满的一天,因为我终于彻底搞定了在debian系编译SSL版的squid的办法!

不知道经过了多少个日夜的研究,探索,一次又一次的失败,我几乎都要放弃了squid的ssl的编译了,我敢打赌:squid是有史以来做的最烂,最难编译的代理软件!
在debian系编译支持SSL的squid,就像一种无法逾越的高山,超越它一直是我心中坚定而又向往的梦想!

就在几分钟前,无意间的浏览看到了一个网友的经验文章,冒着仍然会失败的打击(我已经编译失败了太多次了),决然一试,我操!终于成功了!感谢这位台湾的的网友啊 !(http://ithelp.ithome.com.tw/question/10170306?tab=opinion

下面是在debian系编译支持SSL的squid的方法:

平台: ubuntu 14.04, squid.4.0.4


wget http://www.squid-cache.org/Versions/v4/squid-4.0.4-20160205-r14526.tar.gz

tar -xvzf squid-4.0.4-20160205-r14526.tar.gz

cd squid-4.0.4-20160205-r14526

./configure --prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib/squid  --datadir=/usr/share --includedir=/usr/include  --with-pidfile=/var/run/squid.pid  --disable-strict-error-checking --sysconfdir=/etc/squid --with-logdir=/var/log/squid3 --libdir=/usr/lib/ --with-openssl=/usr/local/ssl/ --enable-ssl --enable-ssl-crtd  --enable-basic-auth-helpers="LDAP,MSNT,NCSA,PAM,SASL,SMB,YP,DB,POP3,getpwnam,squid_radius_auth,multi-domain-NTLM" '--enable-eui' '--enable-follow-x-forwarded-for' '--enable-auth' '--enable-auth-basic=DB,NCSA,NIS,POP3,RADIUS,SMB,getpwnam'  '--enable-auth-digest=file' '--enable-auth-negotiate=kerberos'  '--enable-cache-digests' '--enable-cachemgr-hostname=localhost' '--enable-delay-pools' '--enable-epoll' '--enable-icap-client' '--enable-ident-lookups' '--enable-linux-netfilter' '--enable-removal-policies=heap,lru' '--enable-snmp' '--enable-storeio=aufs,diskd,ufs' '--enable-wccpv2' '--enable-esi' --enable-icmp   '--with-aio' '--with-default-user=squid' '--with-filedescriptors=65536' '--with-dl' --with-large-files --with-swapdir=/var/spool/squid

make LDFLAGS+=-ldl
make install

chmod -R 777 /var/log/squid3/



vi /etc/squid/squid.conf


主要做以下修改(暂时不开启用户认证):


#http_access deny all
http_access allow all


dns_v4_first_on    (这是squid 在debian系SSL能成功的至关重要的一步!)   


# Squid normally listens to port 3128
#http_port 127.0.0.1:3128
https_port 443 cert=/etc/squid/vps.pem key=/etc/squid/vps.pem 


然后ESC :wq 存盘。


然后启动squid

squid /etc/squid/squid.conf


其他的stunnel或者letsencrypt,跟以前一样,随便搞!


啊!debian系的squid SSL终于成功了! 内流满面啊!  操!我终于把squid搞大圆满了!




磊垒

unread,
Feb 12, 2016, 7:15:56 AM2/12/16
to 翻墙论坛
你好!运行squid报错,具体信息如下,请问是什么原因,谢谢!

[root@vultr ~]# squid
FATAL: getpwnam failed to find userid for effective user 'squid'
Squid Cache (Version 4.0.4-20160205-r14526): Terminated abnormally.
CPU Usage: 0.011 seconds = 0.005 user + 0.006 sys
Maximum Resident Size: 25952 KB
Page faults with physical i/o: 0


在 2016年2月7日星期日 UTC+8下午9:06:58,Gary12写道:
...

Gary12

unread,
Feb 14, 2016, 12:45:34 AM2/14/16
to 翻墙论坛
你什么平台? 把运行 squid -v的返回信息贴出来。
另外把你的squid.conf的配置信息也贴出来

在 2016年2月12日星期五 UTC+8下午8:15:56,磊垒写道:
...

hzzhy

unread,
Mar 8, 2016, 9:07:37 PM3/8/16
to 翻墙论坛
出错

FATAL: getpwnam failed to find userid for effective user 'squid'
在 2016年2月7日星期日 UTC+8下午9:06:58,Gary12写道:
关于在VPS部署squid https通道的终极教程(已经彻底解决SSL编译的问题)
...

hzzhy

unread,
Mar 8, 2016, 10:19:20 PM3/8/16
to 翻墙论坛
打不开HTTPS开头的网站,http的能打开。怎么办?


在 2016年2月7日星期日 UTC+8下午9:06:58,Gary12写道:
关于在VPS部署squid https通道的终极教程(已经彻底解决SSL编译的问题)
...

真心猪猪

unread,
Mar 9, 2016, 1:09:09 PM3/9/16
to 翻墙论坛
应该是你编译 squid 的时候,没配置对吧,如果配置和编译没有出问题,肯定可以正常使用的,还有你是用的什么浏览器用这个代理的?

在 2016年3月9日星期三 UTC+8上午11:19:20,hzzhy写道:
...

mee...@gmail.com

unread,
May 21, 2017, 6:04:53 AM5/21/17
to 翻墙论坛
请问  squid+goagent  怎么配置,https 一直处理不了,


在 2016年2月7日星期日 UTC+8下午9:06:58,Gary12写道:
关于在VPS部署squid https通道的终极教程(已经彻底解决SSL编译的问题)

天朝屁民

unread,
May 23, 2017, 4:11:01 AM5/23/17
to 翻墙论坛, mee...@gmail.com
两个完全不同的东西,你混在一起,肯定用不了。

gyjys...@gmail.com

unread,
Jul 18, 2017, 12:34:15 PM7/18/17
to 翻墙论坛

感谢楼主花费这么多经历,分享这么好的技术方案。然而我的问题是,直接通过HTTPS代理的方式上网,会存在被GFW检测到翻墙行为吗?根据ShadowSocks作者的分析,使用SSL翻墙会让GFW嗅探出访问的目标地址以及证书信息,这样看来很容易被墙给封锁掉?不知LZ有无研究过这个问题呢?


Reply all
Reply to author
Forward
0 new messages