安装验证密码install

centos安装http代理squid带验证密码

服务器技术 2021-11-29 14:07:05 35

导读

安装squid yum-yinstallsquid //安装 `#rpm-qa|grepsquid` squid-3.3.8-26.el7_2.4.x86_64//表示已安装 开机自启动squid systemctlenablesquid.service 配置squid vi/etc/squid/squid.conf 找到 http_accessdenyall 在之前添加下面数行内容:注意路……

安装 squid

yum -y install squid // 安装

`# rpm -qa | grep squid`

squid-3.3.8-26.el7_2.4.x86_64            // 表示已安装                         

开机自启动 squid

systemctl enable squid.service

配置 squid

vi /etc/squid/squid.conf 找到 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://106.105.95.26:3128', 'https': 'https://106.105.95.26:3128'}
proxies = {'http': 'http://user:passwd@106.105.95.26:3128', 'https': 'https://user:passwd@106.105.95.26:3128'}
resp = requests.get('http://httpbin.org/ip', proxies=proxies)
print(resp.json())
1253067 TFnetwork_cn