Skip to content

squid

高性能代理服务器,支持FTP、http、https等协议。

配置squid

拉取镜像

sh
sudo docker pull sameersbn/squid

配置文件

squid.conf

sh
acl all src 0.0.0.0/0
acl SSL_ports port 443
acl Safe_ports port 80
acl Safe_ports port 443
acl CONNECT method CONNECT
http_access allow all
http_port 3128
visible_hostname proxy

远程代理服务器开启docker服务

sh
docker run -d --name squid -p 3128:3128 -v /home/ubuntu/squid.conf:/etc/squid/squid.conf sameersbn/squid

本地电脑设置代理

sh
# 根据远程代理服务器访问的方式是否为https进行设置,不确定的话就都设置上
export http_proxy='http://xx.xx.xx.xx:3128'
export https_proxy='https://xx.xx.xx.xx:3128'

#or

export https_proxy='http://xx.xx.xx.xx:3128'

通过wget确认代理是否生效

sh
wget https://www.xxxx.com


--2024-12-21 21:39:35--  https://www.xxxx.com/
Connecting to 49.232.53.251:3128... connected.
Proxy request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.html.13’

index.html.13                               [            <=>                                                                 ] 436.98K   142KB/s    in 3.1s

2024-12-21 21:39:39 (142 KB/s) - ‘index.html.13’ saved [447470]

需要验证或者授权的代理

配置文件

sh
acl localnet src all

acl SSL_ports port 443
acl Safe_ports port 80
acl Safe_ports port 21
acl Safe_ports port 443
acl Safe_ports port 70
acl Safe_ports port 210
acl Safe_ports port 1025-65535
acl Safe_ports port 280
acl Safe_ports port 488
acl Safe_ports port 591
acl Safe_ports port 777
acl CONNECT method CONNECT

# username and password auth config
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/squid_passwd
acl ncsa_users proxy_auth REQUIRED
http_access allow ncsa_users

http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
http_access deny to_localhost
http_access allow localnet
http_access allow localhost
http_access deny all
http_port 3128

refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern (Release|Packages(.gz)*)$ 0       20%     2880
refresh_pattern .               0       20%     4320

安装htpasswd命令

sh
sudo apt install apache2-utils

生成访问用户名密码对

sh
sudo htpasswd -c <filename> <username>

dotohi:$apr1$gewwEbvJ$PGGUSPxPm4OQdoRXnaCh4.

开启docker的squid服务

sh
docker run -d --name squid -p 3128:3128 -v /home/ubuntu/pass_squid.conf:/etc/squid/squid.conf -v /home/ubuntu/squid_pass:/etc/squid/squid_passwd sameersbn/squid