tinyproxy版本1.8.3不支持账号密码验证,而新版本1.10.0支持
1、如果不需要鉴权,可以直接通过yum安装1.8版本
2、需要鉴权则要使用1.10以上版本,yum安装的最新版是1.8,只能通过源码安装
-
yum安装
yum -y install tinyproxy
配置 /etc/tinyproxy/tinyproxy.conf
默认端口是 8888
Port 8888
注释掉 Allow,表示允许所有人访问代理
#Allow 127.0.0.1
隐藏掉Via请求头部,去掉下面的注释
DisableViaHeader Yes
# 多个Allow 表示允许多个客户端ip进行连接
Allow 39.3.2.16
Allow 2.15.9.19
Allow 8.10.133.22
Allow 1.20.7.14
# 权限校验
BasicAuth user 123456
启动服务
systemctl start tinyproxy.service
添加防火墙
firewall-cmd --zone=public --add-port=8888/tcp --permanent
firewall-cmd --reload
然后在本机测试
export https_proxy=http://ip:port
export http_proxy=http://ip:port
curl https://www.baidu.com
# 有权限校验需要
curl -x http://user:123456@127.0.0.1:8888 https://www.baidu.com
Python测试
import requests
PROXY = {
'http': 'ip:port',
'https': 'ip:port'
}
res = requests.get('https://www.baidu.com', proxies=PROXY)
编译安装
wget https://github.com/tinyproxy/tinyproxy/releases/download/1.11.1/tinyproxy-1.11.1.tar.gz
tar xvf tinyproxy-1.11.1.tar.gz
cd tinyproxy-1.11.1/
./configure
make -j 4
make install
which tinyproxy
tinyproxy -v
配置文件路径在源码包
ls etc/tinyproxy.conf
# 复制配置文件
cp etc/tinyproxy.conf /etc/
配置为系统服务
vim /usr/lib/systemd/system/tinyproxy.service
[Unit]
Description=Startup script for the tinyproxy server
After=network.target
[Service]
Type=forking
PIDFile=/var/run/tinyproxy/tinyproxy.pid
ExecStart=/usr/local/bin/tinyproxy -c /etc/tinyproxy.conf
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
[Install]
WantedBy=multi-user.target
启动服务
systemctl daemon-reload
systemctl start tinyproxy