Tinyproxy 是一个轻量级的开源 web 代理守护进程,其设计目标是快而小。它适用于需要完整 HTTP 代理特性,但系统资源又不足以运行大型代理的场景,比如嵌入式部署。
Tinyproxy 对小规模网络非常有用,这样的场合下大型代理会使系统资源紧张,或有安全风险。Tinyproxy 的一个关键特性是其缓冲连接的理念。从效果上看, Tinyproxy 对服务器的响应进行了高速缓冲,然后按照客户端能够处理的最高速度进行响应。该特性极大的降低了网络延滞带来的问题.
在云服务器上安装 TinyProxy
我的是腾讯云的ubuntu主机
sudo apt install tinyproxy
配置 TinyProxy
vim /etc/tinyproxy/tinyproxy.conf
修改port
改 Port 端口,默认为 8888
注释掉 Allow,表示允许所有人访问代理
#Allow 127.0.0.1
启动tinyproxy
systemctl start tinyproxy.service
systemctl restart tinyproxy.service
systemctl stop tinyproxy.service
systemctl status tinyproxy.service
systemctl enable tinyproxy.service
配置防火墙
firewall-cmd --add-port=8888/tcp --permanent
firewall-cmd --reload
查看log
sudo tail -f /var/log/tinyproxy/tinyproxy.log
显示
[sudo] password for andrew:
CONNECT Dec 10 00:52:11 [16620]: Connect (file descriptor 7): 116.243.10.72 [116.243.10.72]
CONNECT Dec 10 00:52:11 [16620]: Request (file descriptor 7): GET http://httpbin.org/ip HTTP/1.1
INFO Dec 10 00:52:11 [16620]: No upstream proxy for httpbin.org
CONNECT Dec 10 00:52:11 [16620]: Established connection to host "httpbin.org" using file descriptor 8.
INFO Dec 10 00:52:12 [16620]: Closed connection between local client (fd:7) and remote client (fd:8)
CONNECT Dec 10 00:52:45 [16623]: Connect (file descriptor 7): 116.243.10.72 [116.243.10.72]
CONNECT Dec 10 00:52:45 [16623]: Request (file descriptor 7): GET http://httpbin.org/ip HTTP/1.1
INFO Dec 10 00:52:45 [16623]: No upstream proxy for httpbin.org
CONNECT Dec 10 00:52:45 [16623]: Established connection to host "httpbin.org" using file descriptor 8.
INFO Dec 10 00:52:45 [16623]: Closed connection between local client (fd:7) and remote client (fd:8)
在客户端设置代理
echo export HTTP_PROXY=http://cloudvirtualmachineIP:8888 >> ~/.bashrc
source ~/.bashrc
验证是否代理成功
在python解释器中
import requests
requests.get('http://httpbin.org/ip').json()
得到你云主机的ip地址就是设置成功了