Admin

树莓派 centos7 使用privoxy转发sock5到http用于终端使用代理
2019年4月24日 22:39 20 0 0 0

目录

privoxy的主要作用就是将sock5代理(shadowsocs/v2ray等本地代理端口)转发为http代理形式,因为终端及很多应用不支持sock5代理。

privoxy源代码/编译/安装

  1. wget "http://www.privoxy.org/sf-download-mirror/Sources/3.0.26 (stable)/privoxy-3.0.26-stable-src.tar.gz"
  2. tar -xvf privoxy-3.0.26-stable-src.tar.gz
  3. cd privoxy-3.0.26-stable
  4. adduser privoxy
  5. yum install cvs -y
  6. autoheader && autoconf && ./configure
  7. make
  8. make install

Tips:

  1. 源码包地址可能要求番茄
  2. privoxy的编译文档不建议使用root,需要新建用户和用户组:privoxy
  3. 安装路径为:/usr/local/etc/privoxy/usr/local/bin/privoxy

配置文件

  1. vim /usr/local/etc/privoxy/config

找到 listen 关键字, 修改监听地址(默认是:127.0.0.1)和端口(默认:8118):

  1. # Example:
  2. #
  3. # Suppose you are running Privoxy on a machine which has the
  4. # address 192.168.0.1 on your local private network
  5. # (192.168.0.0) and has another outside connection with a
  6. # different address. You want it to serve requests from inside
  7. # only:
  8. #
  9. # listen-address 192.168.0.1:8118
  10. #
  11. # Suppose you are running Privoxy on an IPv6-capable machine and
  12. # you want it to listen on the IPv6 address of the loopback
  13. # device:
  14. #
  15. # listen-address [::1]:8118
  16. #
  17. listen-address 0.0.0.0:8118

找到 forward 关键字,修改(取消注释)转发sock5地址(1081是我的v2ray客户端本地端口)和跳过转发的本地地址:

  1. # To chain Privoxy and Tor, both running on the same system, you
  2. # would use something like:
  3. #
  4. forward-socks5t / 127.0.0.1:1081 .
  5. #
  6. # Note that if you got Tor through one of the bundles, you may
  7. # have to change the port from 9050 to 9150 (or even another
  8. # one). For details, please check the documentation on the Tor
  9. # website.
  10. #
  11. # The public Tor network can't be used to reach your local
  12. # network, if you need to access local servers you therefore
  13. # might want to make some exceptions:
  14. #
  15. forward 192.168.*.*/ .
  16. forward 10.*.*.*/ .
  17. forward 127.*.*.*/ .

启动服务

  1. systemctl start privoxy

测试代理

  1. curl -x 127.0.0.1:8118 https://www.youtube.com

能够访问并打印网页内容即为成功

终端环境变量

  1. export http_proxy=http://127.0.0.1:8118
  2. export https_proxy=http://127.0.0.1:8118
  3. export ftp_proxy=http:>//127.0.0.1:8118

也可以将上述命令复制到~/.bashrc或者/etc/profile末尾,实现自动使用环境变量。

开机自动启动服务

  1. systemctl enable privoxy

参考链接

https://note.xdq.me/centos-7-an-zhuang-privoxy-2/
https://www.5yun.org/14197.html
https://blog.acesheep.com/index.php/archives/54/#comment-221

发布内容,请遵守相关法律法规。
评论