CentOS 7 搭建 TinyProxy 代理 &&python 脚本访问

TinyProxy

TinyProxy 和 Squid 都是比較優秀的代理軟件

TinyProxy比較小眾,雖然沒有Squid的功能豐富,但是小巧簡單,也能滿足普通用戶的需求。

Squid 是一款優秀的代理軟件,有很豐富的ACL管理功能,雖然squid很強大,但配置比較繁瑣。

 

 

1. 安裝 TinyProxy

yum -y install tinyproxy

 

 

2. 配置 TinyProxy

复制代码
vim /etc/tinyproxy/tinyproxy.conf

修改 Port 端口,默認為 8888

Port 8888

註釋掉 Allow,表示允許所有人訪問代理

#Allow 127.0.0.1

隱藏掉Via請求頭部,去掉下面的註釋

DisableViaHeader Yes

更多配置項,下面是列舉一些配置文件默認的,不需要配置:

PidFile "/var/run/tinyproxy/tinyproxy.pid"
LogFile "/var/log/tinyproxy/tinyproxy.log"
LogLevel Info
MaxClients 100
MinSpareServers 5
MaxSpareServers 20
StartServers 10
复制代码

 

3. 启动 TinyProxy

systemctl start tinyproxy.service

更多命令如下:

systemctl restart tinyproxy.service #重啟
systemctl stop tinyproxy.service   #停止
systemctl status tinyproxy.service   #檢查
systemctl enable tinyproxy.service   #開機啟動

 

4.增加Python 脚本访问

复制代码
import requests


proxy = {
    'http': 'http://101.32.00.000:8888',
    'https': 'http://101.32.00.000:8888'
}

html = requests.get("http://i.pinimg.com/originals/e2/8a/3e/e28a3e0fa51fa68c0a79578d4485b928.jpg", proxies=proxy,
                    verify=False)

print(html.status_code)
with open('/tmp/ffff.jpg', 'wb') as file:
    file.write(html.content)
复制代码

 

posted on   星河赵  阅读(578)  评论(0编辑  收藏  举报

编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
历史上的今天:
2019-01-14 fork分支与源分支同步代码
2017-01-14 ubuntu16系统中pycharm下使用git将代码提交到github仓库
2017-01-14 解决Ubuntu16的风扇高速旋转问题(双显卡)

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示