树莓派用privoxy自动代理

首先说明下,本文是以树莓派作为客户端连接ss, 再用privoxy自动代理实现科学研究。
1 安装ss apt-get install shadowsocks-libev

2 禁用这个服务端服务 systemctl disable shadowsocks-libev

3 自动开启这个客户端连接服务 systemctl enable shadowsocks-libev-local@config

4 编辑ss的配置文件 vi /etc/shadowsocks-libev/config.json

{
    "server":"114.0.114.0",
    "server_port":8388,
    "local_address":"0.0.0.0",
    "local_port":1080,
    "password":"123456",
    "timeout":600,
    "method":"aes-256-cfb"
}

5 重启客户端连接服务systemctl restart shadowsocks-libev-local@config

6 安装privoxy apt-get install privoxy,作用是将sock5转为http代理

7 配置privoxy vi /etc/privoxy/config
filter 部分注释掉

# 大约在435行
# filterfile default.filter
# filterfile user.filter      # User customizations

默认的 action 文件注释掉,并添加自定义文件

# 386行左右
# 默认的 action 文件
# actionsfile match-all.action # Actions that are applied to all sites and maybe overruled later on.
# actionsfile default.action   # Main actions file
# actionsfile user.action      # User customizations
# 自定义 action 文件
actionsfile my.action

8 编辑自定义的action文件 vi /etc/privoxy/my.action

# 这一行表示本 action 文件中所有条目都使用代理
{+forward-override{forward-socks5 127.0.0.1:1080 .}}
# 添加一条规则
.google.com
.github.com
raw.githubusercontent.com

9 重启privoxy服务systemctl restart privoxy.service

10 测试下规则, 执行这个 curl时可以走代理

export http_proxy=http://127.0.0.1:8118;export https_proxy=http://127.0.0.1:8118;

测试下 curl google.com

11 用gfwlist2privoxy生自代理规则
curl -4sSkLO https://raw.github.com/zfl9/gfwlist2privoxy/master/gfwlist2privoxy
如果打不开,可以先想办法保存下来,再进行下一步。

bash gfwlist2privoxy 127.0.0.1:1080,注意将 127.0.0.1:1080 替换为你的 socks5 地址

mv -f gfwlist.action /etc/privoxy/,将 gfwlist.action 移动到 privoxy 配置文件目录

echo 'actionsfile gfwlist.action' >>/etc/privoxy/config,应用 gfwlist.action 配置文件

systemctl restart privoxy.service,重启 privoxy 服务,留意 privoxy 运行状态,检查是否有错误

12 再测试下,如curl -ik https://www.twitter.com ,响应可能是这样的:

HTTP/1.1 200 Connection established

HTTP/2 301 
cache-control: no-cache, no-store, max-age=0
content-length: 0
date: Fri, 03 Jul 2020 18:12:48 GMT
location: https://twitter.com/
server: tsa_m
set-cookie: personalization_id="v1_+VOCbATREkvyKYORVAdUfA=="; Max-Age=63072000; Expires=Sun, 3 Jul 2022 18:12:48 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None
set-cookie: guest_id=v1%3A159379996818764706; Max-Age=63072000; Expires=Sun, 3 Jul 2022 18:12:48 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None
strict-transport-security: max-age=631138519
x-connection-hash: 0bcef9aaaaff109b622e6d6e5135cc2e
x-response-time: 100

参考文章:
https://github.com/zfl9/gfwlist2privoxy
https://juejin.im/post/5c91ff5ee51d4534446edb9a