文章目录
TinyProxy 搭建代理 爬虫
一、首先安装tinyproxy
执行命令 yum -y install tinyproxy
找不到安装包的时候可以装一下epel。
安装 yum install epel-release
二、配置
编辑tinyproxy的配置文件
1 |
vi /etc/tinyproxy/tinyproxy.conf |
1.更改端口,默认8888。可以更改为自己喜欢的端口,也可不修改,直接使用8888端口。
1 2 3 4 5 6 7 8 9 |
User tinyproxy Group tinyproxy # # Port: Specify the port which tinyproxy will listen on. Please note # that should you choose to run on a port lower than 1024 you will need # to start tinyproxy using root. # Port 1023 # 我修改成了 1023 |
阿里云 或者 腾讯云记得打开响应的口访问权限
2.修改允许连接代理的ip。默认只允许本地。
1 2 3 4 5 6 7 |
# the default action is ALLOW. # # The order of the controls are important. All incoming connections are # tested against the controls based on order. # Allow 0.0.0.0/0 # 允许全部ip可以访问 |
3.开启服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
(base) ➜ ~ systemctl start tinyproxy.service ● tinyproxy.service - Startup script for the tinyproxy server Loaded: loaded (/usr/lib/systemd/system/tinyproxy.service; enabled; vendor preset: disabled) Active: active (running) since 一 2021-08-30 09:27:13 CST; 9s ago Process: 450061 ExecStart=/usr/sbin/tinyproxy -c /etc/tinyproxy/tinyproxy.conf (code=exited, status=0/SUCCESS) Main PID: 450063 (tinyproxy) CGroup: /system.slice/tinyproxy.service ├─450063 /usr/sbin/tinyproxy -c /etc/tinyproxy/tinyproxy.conf ├─450065 /usr/sbin/tinyproxy -c /etc/tinyproxy/tinyproxy.conf ├─450068 /usr/sbin/tinyproxy -c /etc/tinyproxy/tinyproxy.conf ├─450069 /usr/sbin/tinyproxy -c /etc/tinyproxy/tinyproxy.conf ├─450070 /usr/sbin/tinyproxy -c /etc/tinyproxy/tinyproxy.conf ├─450071 /usr/sbin/tinyproxy -c /etc/tinyproxy/tinyproxy.conf ├─450072 /usr/sbin/tinyproxy -c /etc/tinyproxy/tinyproxy.conf ├─450073 /usr/sbin/tinyproxy -c /etc/tinyproxy/tinyproxy.conf ├─450074 /usr/sbin/tinyproxy -c /etc/tinyproxy/tinyproxy.conf ├─450075 /usr/sbin/tinyproxy -c /etc/tinyproxy/tinyproxy.conf |
三、验证
多种验证方式
1,可以使用curl,在需要代理的机器上执行命令。
1 2 3 4 5 6 7 8 9 10 11 12 13 |
❯ curl -x 123.56.250.187:1023 httpbin.org/get { "args": {}, "headers": { "Accept": "*/*", "Host": "httpbin.org", "User-Agent": "curl/7.71.1", "X-Amzn-Trace-Id": "Root=1-612c3798-5374d0d23a5e233630aa8e56" }, "origin": "123.56.250.187", "url": "http://httpbin.org/get" } |
2, 可以使用 Python 验证
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
In [12]: import requests In [13]: url = "https://httpbin.org/get" proxies = {'https': '123.56.250.187:1023','http': '123.56.250.187:1023'} In [14]: res=requests.get(url,proxies=proxies,timeout=10) In [15]: res.json() Out[15]: {'args': {}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Host': 'httpbin.org', 'X-Amzn-Trace-Id': 'Root=1-612c3957-4e7ae1322a5ccb2b4ed32e1d'}, 'origin': '123.56.250.187', 'url': 'https://httpbin.org/get' |
也可以使用其他验证方式,如浏览器使用此代理,访问获取本地ip的网站等。
若验证失败,可能是端口没开,使用iptables开放端口。
1 |
iptables -I INPUT -p tcp --dport 4396 -j ACCEPT |
tinyproxy总结:
*tinyproxy对于IP代理来说满足了最基本的需求。
*资源消耗较小,配置简单。
*http,https均支持。
*这种代理方式是透明代理。

不错,必须顶一下!