代理服务器
     分类:环境搭建     有: 0 条评论

代理服务器

     分类:环境搭建     有: 0 条评论

搭建http代理服务器

Centos 7 搭建

这里使用了centos7自带的squid代理软件

yum install squid httpd-tools -y

# 用户名密码认证
htpasswd -bc  /etc/squid/passwords [用户名] [密码]
chmod o+r /etc/squid/passwords

# ----------------------------------------------------------
vim /etc/squid/squid.conf

#配置用户名密码,后面会生成passwords文件
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwords
auth_param basic realm proxy
acl authenticated proxy_auth REQUIRED #添加IP白名单(通过认证的都接受)
http_access allow authenticated

http_access deny all # 这一句要在其他http_access allow之后

#这里是端口号,可以按需修改,同时监听ipv6和ipv4的端口
http_port 0.0.0.0:3128


# ----------------------------------------------------------
检查squid配置是否正确(如果有错误,会显示错误内容,按相应的改就行。)
squid -z


开启squid服务
systemctl start squid
systemctl status squid
systemctl stop firewalld 或者放行端口


squid的日志文件:/var/log/squid/access.log

参考资料:
https://blog.csdn.net/qingfengxulai/article/details/80853870
https://blog.csdn.net/a519395243/article/details/82463637
https://blog.csdn.net/Qwertyuiop2016/article/details/90183014



检测代理

from urllib import request

if __name__ == "__main__":
    # 访问网址
    url = 'https://www.leolan.top'
    # 这是代理IP
    proxy = {'http': 'http://[账户]:[密码]@[代理IP]:[代理端口]'}
    # 创建ProxyHandler
    proxy_support = request.ProxyHandler(proxy)
    # 创建Opener
    opener = request.build_opener(proxy_support)
    # 添加User Angent
    opener.addheaders = [('User-Agent',
                          'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36')]
    # 安装OPener
    request.install_opener(opener)
    # 使用自己安装好的Opener
    response = request.urlopen(url, timeout=5)
    # 读取相应信息并解码
    html = response.read().decode("utf-8")
    # 打印信息
    print(html)
(●゚ω゚●)