安装 squid
#Suid安装命令
yum -y install squid
查看是否安装成功
rpm -qa | grep squid
#表示已安装
squid-3.3.8-26.el7_2.4.x86_64
开机自启动 squid
systemctl enable squid.service
配置 Squid
#编辑squid配置文件
vi /etc/squid/squid.conf
#找到
http_access deny all
在 http_access deny all
前添加下面数行内容:注意路径
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd
auth_param basic children 5
auth_param basic realm hehe
auth_param basic credentialsttl 2 hours
# 验证用户
acl myproxy_User proxy_auth REQUIRED
# 运行该用户
http_access allow myproxy_User
增加2句隐藏真实ip变成匿名代理 这是squid 3.1的写法
via off
forwarded_for delete
squid 用户名密码认证
如果你想让用户使用之前,对其身份进行验证。你可能会用到squid的基本认证特性。
这里我们会用到一个工具 httpd-tools,其包含了htpasswd指令用于创建加密密码文件。
#使用如下指令安装:
yum -y install httpd
yum -y install htpd-tools
生成密码文件
touch /etc/squid/passwd && chown squid /etc/squid/passwd
添加认证用户
htpasswd /etc/squid/passwd myproxy_User
命令行会询问输入密码和一次确认密码,输入就是。请记住,这个密码是myproxy_User 用户的。
默认htpasswd使用MD5给密码加密的,存储的当然也就是MD5哈希值。
查看用户/密码
cat /etc/squid/passwd
用户和密码都就位了,接着我们向squid配置文件内添加允许授权用户访问。在安全端口设置下方加入以下配置行
接得修改完配置重启squid服务。重启后生效。
启动服务
systemctl start squid.service
查看服务运行占用的端口
netstat -ntpl
可以看到3128已经在运行服务了
这时别忘了防火墙把3128端口打开
代理测试
wget命令行
wget -e "https_proxy=https://user:passwd@106.105.95.26:3128/" https://www.baidu.com/
Python requests示例
import requests
proxies = {'http': 'http://192.168.16.12:3128', 'https': 'https://192.168.16.12:3128'}
proxies = {'http': 'http://user:passwd@192.168.16.12:3128', 'https': 'https://user:passwd@192.168.16.12:3128'}
resp = requests.get('http://httpbin.org/ip', proxies=proxies)
print(resp.json())
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
my ex likes my pictures on instagram3年前0
Hey there great blog! Does running a blog like this take a massive amount work? I've virtually no understanding of computer programming but I had been hoping to start my own blog in the near future. Anyways, if you have any suggestions or techniques for new blog owners please share. I understand this is off topic but I simply needed to ask. Kudos!Twicsy3年前0
Hi, i think that i saw you visited my site thus i came to “return the favor”.I'm trying to find things to enhance my web site!I suppose its ok to use a few of your ideas!!