CentOS上使用Squid+Stunnel搭建代理服务器教程

2020-01-30 14:36:25王旭


VPS很少有,自启动开启防火墙的,如果有先关掉,等都配置好了,在开放端口。


三,客户端安装配置stunnel
1,安装

复制代码
# yum install stunnel

2,新增配置/etc/stunnel/stunnel.conf,添加以下内空

复制代码
client = yes
fips = no
[https]
accept = 7071
connect = 外网VPS的IP:4430

如果报,FIPS_mode_set: 2D06C06E: error:2D06C06E:FIPS routines:FIPS_module_mode_set:fingerprint does not match,stunnel.conf配置文件中加上,fips = no
3,启动stunnel并查看

复制代码
# stunnel //启动,默认配置文件路径 /etc/stunnel/stunnel.conf

# ps aux |grep stunnel //查看
root 15972 0.0 0.0 103256 848 pts/0 S+ 17:30 0:00 grep stunnel
root 21099 0.0 0.0 41532 1060 pts/0 S 15:42 0:00 stunnel
root 21100 0.0 0.0 41532 1060 pts/0 S 15:42 0:00 stunnel
root 21101 0.0 0.0 41532 1060 pts/0 S 15:42 0:00 stunnel
root 21102 0.0 0.0 41532 1060 pts/0 S 15:42 0:00 stunnel
root 21103 0.0 0.0 41532 1060 pts/0 S 15:42 0:00 stunnel
root 21104 0.0 0.0 2077984 6824 ? Ss 15:42 0:00 stunnel

到这儿就安装好了,设置浏览器代理,填写局域网IP和端口,就可以访问外网了,这样不太安全,如果能加上用户认证会,安全一点。

四,用户认证
1,添加认证用户 test123

复制代码
# htpasswd -c /etc/squid/passwd test123

2,配置代理以及用户认证

复制代码
# vim /etc/squid/squid.conf //添加以下内容

auth_param basic program /usr/lib64/squid/ncsa_auth /etc/squid/passwd //认证方式为basic,认证程序路径和密码文件路径
auth_param basic children 5 //认证程序的进程数
auth_param basic credentialsttl 1 hours //认证有效时间
auth_param basic realm my test prosy //浏览器显示输入用户/密码对话框时,显示的内容
acl test123 proxy_auth REQUIRED
http_access allow test123 //普通用户需要通过认证才能访问
http_access deny all //最下面,匹配是从上到下的

3,重启squid

复制代码
# /etc/init.d/squid restart

这样squid代理就搭好了,浏览器里面设置一下代理IP和端口,会弹出认证框,输入用户名和密码就行了。
4,php也可以利用代理服务器

复制代码
function testCurl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $gurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);