Skip to content

Instantly share code, notes, and snippets.

@shellexy
Created February 27, 2019 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shellexy/518189b2dee475215e0c56f7ef3c9196 to your computer and use it in GitHub Desktop.
Save shellexy/518189b2dee475215e0c56f7ef3c9196 to your computer and use it in GitHub Desktop.
让 privoxy 代理服务器使用 gfwlist 自动分流
#!/bin/bash -x
## 让 privoxy 代理服务器使用 gfwlist 自动分流
## 安装需要的包,gfwlist2privoxy 暂时只支持 py2.7 所以需要修改下::
# sudo apt install -y privoxy python-pip
# pip install --user gfwlist2privoxy
# sed -i 's,^#!/usr/bin/python.*,#!/usr/bin/python2.7,' ~/.local/bin/gfwlist2privoxy
## 修改 privoxy 配置,默认使用 8123 本地端口
grep -q gfwlist.action /etc/privoxy/config || echo 'actionsfile gfwlist.action' | sudo tee -a /etc/privoxy/config
grep -P '^listen-address\s+\d' /etc/privoxy/config || echo 'listen-address 0.0.0.0:8123' | sudo tee -a /etc/privoxy/config
## 用户规则
cat > user.rule <<EOF
.ajax.cloudflare.com
.amazonaws.com
.apkmirror.com
.bitbucket.com
.blogspot.tw
.cc
.cefamilie.com
.contentabc.com
.ecchi.iwara.tv
.frantech.ca
.github.io
.githubassets.com
.githubusercontent.com
.jianshu.com
.jimpop.org
.me
.phncdn.com
.pw
.python.org
.sosreader.com
.teamviewer.com
.tellapart.com
.webupd8.org
.yubico.com
EOF
## gfwlist2privoxy 只认 https_proxy 环境变量,不认 HTTP_PROXY
export https_proxy=127.0.0.1:8123
## 生成 gfwlist.action 后刷新 privoxy
time gfwlist2privoxy -p 127.0.0.1:7070 -t socks5t -f gfwlist.action --user-rule user.rule &&
sudo cp gfwlist.action /etc/privoxy/ &&
sudo service privoxy force-reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment