centos7下使用Privoxy将socket5转http代理

Published on Feb 9, 2017 ,1 min reading time

shadowsocks是一个socket5的服务,对此,可以使用Privoxy将其转化为http

1.部署shadowsocks

# 安装
pip install shadowsocks
# 创建配置文件
vim /etc/shadowsocks.json
# 输入
{
  "server": "*.*.*.*",
  "server_port": 443,
  "password": "***",
  "method": "aes-256-cfb",
  "local_address": "0.0.0.0",
  "local_port": 1080,
  "workers": 1
}
# 运行
sslocal -c /etc/shadowsocks.json
# 测试当前ip
curl --socks5 127.0.0.1:1080 http://httpbin.org/ip
#返回结果
{
  "origin": "*.*.*.*"
}

说明代理成功,接下来安装Privoxy

2.socket5转http

yum install -y privoxy
# 编辑配置文件
vim /etc/privoxy/config
# 添加
forward-socks5 / 127.0.0.1:1080 .
systemctl restart privoxy
systemctl status privoxy

若果需要在外网访问,则需在/etc/privoxy/config添加listen-address 0.0.0.0:8118,同时还需要将8118端口开启,假设使用iptables:

/etc/sysconfig/iptables
# 添加
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8118 -j ACCEPT
# 重启
systemctl restart iptables
systemctl status iptables
# 测试
vim ~/.bashrc
export http_proxy=http://127.0.0.1:8118   
export https_proxy=http://127.0.0.1:8118
# 成功会有一大串返回
curl www.google.co

3.题外话

顺便一提,如果使用的是mac,需要使用代理服务,若已经配置好shadowsocks

brew install privoxy
vim /usr/local/etc/privoxy/config
# 添加
listen-address 0.0.0.0:8118
forward-socks5 / 127.0.0.1:1080 .
# 开启
/usr/local/sbin/privoxy /usr/local/etc/privoxy/config