Skip to content

Instantly share code, notes, and snippets.

@xwsg
Last active December 5, 2019 02:18
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save xwsg/5ecd015be95a61875d43df87c451aca4 to your computer and use it in GitHub Desktop.
Save xwsg/5ecd015be95a61875d43df87c451aca4 to your computer and use it in GitHub Desktop.
socks5转换为 http 代理(使用privoxy)

目前只测试了Mac和Ubuntu

1.安装 privoxy

Mac

brew install privoxy

ubuntu

sudo apt-get install privoxy

2.配置 privoxy

Mac

vi /usr/local/etc/privoxy/config

Ubuntu

sudo vi /etc/privoxy/config 

注释掉

listen-address  localhost:8118

在最后一行添加

forward-socks5t   /               127.0.0.1:1080 .
listen-address  127.0.0.1:8118

127.0.0.1:1080 为 socks5代理地址及端口

127.0.0.1:8118 为转换为http 代理后的地址及端口,8118如果被占用,可以修改,比如我使用的是10800, 方便记忆

3.启动 privoxy

Mac

/usr/local/sbin/privoxy /usr/local/etc/privoxy/config

Ubuntu

sudo service privoxy restart

4.使用http代理

# http://127.0.0.1:8118 为第2部具体配置的listen-address
export http_proxy='http://127.0.0.1:8118' 
export https_proxy=$http_proxy

5.配置自定义快捷命令

Mac

vi ~/.bash_profile

Ubuntu

vi ~/.bashrc

如果使用的是zsh 修改

vi ~/.zshrc

添加

alias proxyon="export http_proxy='http://127.0.0.1:8118'; export https_proxy=$http_proxy"
alias proxyoff="unset http_proxy; unset https_proxy"

使配置生效

Mac

source ~/.bash_profile

Ubuntu

source ~/.bashrc

如果使用的zsh

source ~/.zshrc

后续开启代理使用proxyon命令即可,关闭代理使用proxyoff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment