squid
是一款高性能的代理缓存服务器,常用来部署HTTP(S)
代理服务器。本文是在Ubuntu
上使用squid
部署HTTP(S)
代理服务器的方法总结。
使用的Ubuntu版本是:Ubuntu 16.04 x64
。
使用如下命令安装squid
:
apt install squid -y
安装后,会在/etc/squid
目录下生成默认的配置文件squid.conf
,需要对其做一些自定义的修改.
将http_port 3128
这行中的3128
修改为期望的端口号,比如8080
,或是非常用端口,这样可以避免服务被shodan之类的搜索引擎探测到。
squid默认只能从本地访问,是因为它设置了http_access allow localhost
。
但正常情况下,我们都是需要从外部访问的,这就需要添加以下两行配置:
acl net src 0.0.0.0/0
http_access allow net
表示接收任意外部地址。
CONNECT
所有端口squid默认只可以CONNECT
443端口,如果要开放所有端口,需要注释掉http_access deny CONNECT !SSL_ports
这行。
squid默认策略只允许代理访问以下端口:
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
因此,会有部分端口无法访问,直接返回403 Forbidden
。如果需要访问这些端口,可以增加以下配置:
acl Safe_ports port 1-1024
squid默认允许访问本地(localhost
)服务,但建议去掉#http_access deny to_localhost
的注释
如果觉得以上操作过于繁琐,在不考虑安全性
的情况下,也可以修改http_access deny all
为http_access allow all
为了安全,我们通常会给代理服务器设置密码。
先安装htpasswd
工具,使用如下命令:
apt install apache2-utils -y
创建密码文件:
htpasswd -c /etc/squid/passwd proxy_username
在squid.conf
中添加以下内容:
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd
systemctl start squid
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有