我的博客
欢迎来到我的博客
bunny.icu

安装Squid代理服务器

安装Squid代理服务器

关闭防火墙

systemctl stop firewalld.service
systemctl disable firewalld.service

如果使用云服务器,可能还需要配置安全组

安装squid和apache

yum install -y squid
yum install -y httpd

创建用户

# squid_user是用户名,可以替换
htpasswd -c /etc/squid/passwd squid_user
# 输入密码
# 文件 /etc/squid/passwd 会自动生成

配置squid授权

vi /etc/squid/squid.conf

修改以下几行

auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd
acl auth_user proxy_auth REQUIRED
http_access allow auth_user

也可以直接把下面的内容复制到配置文件/etc/squid/squid.conf

acl localnet src 10.0.0.0/8     # RFC1918 possible internal network
acl localnet src 172.16.0.0/12  # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl localnet src fc00::/7       # RFC 4193 local private network range
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines

acl SSL_ports port 443
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
acl CONNECT method CONNECT

auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd
acl auth_user proxy_auth REQUIRED
http_access allow auth_user

http_port 3128

coredump_dir /var/spool/squid

refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|?) 0     0%      0
refresh_pattern .               0       20%     4320

启动squid

systemctl start squid
systemctl enable squid
# 查看状态
# systemctl status squid

在python爬虫中的使用

import requests
url = "https://baidu.com"
proxy_url = "http://[用户名]:[密码]@[服务器ip]:3128"
proxies = {"http": proxy_url, "https": proxy_url}
response = requests.get(url, proxies=proxies, headers=headers)

服务器ip也可以换成域名
如果不能用,可能是端口被封,可以考虑修改端口

在Windows 10/11中的使用

网络 & Internet > 代理 > 手动设置代理,填写代理服务器IP和端口

在Mozilla Firefox中的使用

Mozilla Firefox可以使用系统代理,也可以单独设置
访问about:preferences#general,点击最下方的网络设置,填写代理服务器IP和端口

版权声明


本作品系原创, 转载须遵循 CC BY-NC-ND 4.0 许可协议
本文标题:安装Squid代理服务器
本文链接:https://www.bunny.icu/archives/737

推荐文章

发表评论

textsms
account_circle
email

bunny.icu

安装Squid代理服务器
代理服务器Squid的安装和使用
扫描二维码继续阅读
2021-03-06