如何安装 SQUID 代理服务器
最快的代理服务器运行方法是通过 Docker 运行:
docker run --name squid -p 3128:3128 --rm -d \
-e PROXYLOGIN=mylogin \
-e PROXYPASSWORD=mypassword \
anticaptcha/squid
如果要设置自己的配置文件,则要从中设置身份验证方式,然后将其添加到 /etc/squid/squid.conf 中
docker run --name squid -p 3128:3128 --rm -d \
-v /path/to/squid.conf:/etc/squid/squid.conf \
anticaptcha/squid
另一种方法是通过源代码建立代理服务器:
yum -y install make gcc gcc-c++ libtool wget httpd-tools
wget http://www.squid-cache.org/Versions/v3/3.2/squid-3.2.3.tar.gz
tar -zxf squid-3.2.3.tar.gz
cd squid-3.2.3
./configure
make
make install
配置文件示例:
#configure the port number
http_port 9191
cache_mem 5 MB
cache_dir ufs /usr/local/squid/var/cache 300 16 256
cache_access_log /usr/local/squid/var/logs/access.log
cache_log /usr/local/squid/var/logs/cache.log
cache_store_log /usr/local/squid/var/logs/store.log
pid_filename /usr/local/squid/var/logs/squid.pid
auth_param basic program /usr/local/squid/libexec/basic_ncsa_auth /usr/local/squid/etc/squid_users
auth_param basic children 5
auth_param basic realm enter_your_pass
auth_param basic credentialsttl 2 hours
error_directory /usr/local/squid/share/errors/
acl SSL_ports port 443
acl Safe_ports port 80 8080 3128 # http
acl Safe_ports port 443# https
acl CONNECT method CONNECT
acl MYUSERS proxy_auth REQUIRED
acl to_ipv6 dst ipv6
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow net
#allow only athorized users
http_access allow MYUSERS
http_reply_access allow all
icp_access deny all
miss_access allow all
#squid will run under nobody user
cache_effective_user nobody
cache_effective_group nobody
coredump_dir /usr/local/squid/var/cache
## making it anonymous
forwarded_for transparent
request_header_access Via deny all
request_header_access X-Forwarded-For deny all
request_header_access Cache-Control deny all
SQUID 将登录名和密码保存在另一文件中,对于我们来说,该文件是“/usr/local/squid/etc/squid_users”。要管理此文件,请使用“htpasswd”工具:
htpasswd -c /usr/local/squid/etc/squid_users mylogin
完成配置后,要更改 SQUID 目录的权限,并将其作为守护程序运行:
chown -R nobody:nobody /usr/local/squid/share /usr/local/squid/var
/usr/local/squid/sbin/squid -z /usr/local/squid/etc/squid.conf
/usr/local/squid/sbin/squid -f /usr/local/squid/etc/squid.conf
核实代理服务器是否正在运行并且在接受连接:
netstat -lenp|grep squid curl -x IP_HERE:3128 -U mylogin:mypassword http://antigate.com/iptest.php