Privoxy 代理服务器配置指南
![]()
Privoxy 是一个非缓存的 Web 代理服务器,常用于配合 SOCKS5 代理(如 Shadowsocks)进行网络流量转发。本文介绍 Privoxy 的安装、基本配置和代理规则设置。
Privoxy 简介
Section titled “Privoxy 简介”Privoxy 主要功能:
- HTTP 代理:作为 HTTP/HTTPS 代理服务器
- 流量转发:将请求转发到 SOCKS5 代理
- 规则过滤:支持基于域名的转发规则
- 隐私保护:去除广告和跟踪器
安装 Privoxy
Section titled “安装 Privoxy”Ubuntu / Debian
Section titled “Ubuntu / Debian”sudo apt updatesudo apt install privoxyCentOS / RHEL
Section titled “CentOS / RHEL”sudo yum install privoxy# 使用 Homebrewbrew install privoxy安装后配置文件位置:
- Linux:
/etc/privoxy/config - macOS:
/usr/local/etc/privoxy/config - Windows:
C:\Program Files (x86)\Privoxy\config.txt
Windows
Section titled “Windows”- 从 Privoxy 官网 下载安装程序
- 运行安装程序并按提示操作
- 配置文件通常位于
C:\Program Files (x86)\Privoxy\config.txt
Ubuntu / Debian
Section titled “Ubuntu / Debian”sudo apt updatesudo apt install privoxyCentOS / RHEL
Section titled “CentOS / RHEL”sudo yum install privoxy# Using Homebrewbrew install privoxyAfter installation, the config file is located at /usr/local/etc/privoxy/config.
Windows
Section titled “Windows”- Download the installer from the Privoxy website.
- Run the installer and follow the prompts.
- The config file is typically located at
C:\Program Files (x86)\Privoxy\config.txt.
配置代理转发规则
Section titled “配置代理转发规则”在 Privoxy 配置文件中添加转发规则:
forward-socks5 .example.com 127.0.0.1:1080 .语法说明:
forward-socks5:使用 SOCKS5 协议转发.example.com:要转发的域名(以点开头表示所有子域名)127.0.0.1:1080:SOCKS5 代理服务器地址.:转发规则的结束标记
配置文件位置
Section titled “配置文件位置”- Linux:
/etc/privoxy/config或/etc/privoxy/user.action - macOS:
/usr/local/etc/privoxy/config - Windows:
C:\Program Files (x86)\Privoxy\config.txt
以下是一个完整的配置示例,展示了常见的转发规则:
# 基础配置listen-address 127.0.0.1:8118forward-socks5 / 127.0.0.1:1080 .
# 特定域名转发规则forward-socks5 .wikipedia.org 127.0.0.1:1080 .forward-socks5 .github.com 127.0.0.1:1080 .forward-socks5 .google.com 127.0.0.1:1080 .forward-socks5 .youtube.com 127.0.0.1:1080 .forward-socks5 .twitter.com 127.0.0.1:1080 .forward-socks5 .reddit.com 127.0.0.1:1080 .启动/停止/重启服务
Section titled “启动/停止/重启服务”Linux (systemd)
Section titled “Linux (systemd)”# 启动服务sudo systemctl start privoxy
# 停止服务sudo systemctl stop privoxy
# 重启服务sudo systemctl restart privoxy
# 设置开机自启sudo systemctl enable privoxy
# 查看状态sudo systemctl status privoxymacOS (Homebrew)
Section titled “macOS (Homebrew)”# 启动服务brew services start privoxy
# 停止服务brew services stop privoxy
# 重启服务brew services restart privoxyWindows
Section titled “Windows”# 使用服务管理器net start privoxynet stop privoxy验证代理是否工作
Section titled “验证代理是否工作”# 测试 HTTP 代理curl --proxy http://127.0.0.1:8118 https://httpbin.org/ip
# 测试 HTTPS 代理curl --proxy http://127.0.0.1:8118 https://httpbin.org/headers查看 Privoxy 日志
Section titled “查看 Privoxy 日志”# Linux/macOStail -f /var/log/privoxy/logfile
# Windows# 查看安装目录下的 log 文件1. Privoxy 无法启动
Section titled “1. Privoxy 无法启动”问题:服务启动失败或端口被占用。
解决方案:
# 检查端口占用sudo lsof -i :8118
# 修改默认端口(在配置文件中)listen-address 127.0.0.1:81192. 代理规则不生效
Section titled “2. 代理规则不生效”问题:配置了转发规则但没有生效。
解决方案:
- 检查配置文件语法是否正确
- 确保 SOCKS5 代理服务正在运行
- 重启 Privoxy 服务:
sudo systemctl restart privoxy
3. 无法连接到特定网站
Section titled “3. 无法连接到特定网站”问题:某些网站仍然无法访问。
解决方案:
- 检查域名是否正确添加到转发规则
- 尝试使用完整的域名而不是通配符
- 查看 Privoxy 日志获取详细错误信息
4. 浏览器无法使用代理
Section titled “4. 浏览器无法使用代理”问题:浏览器配置了代理但无法工作。
解决方案:
- 确保浏览器代理设置指向
127.0.0.1:8118 - 检查防火墙是否阻止了代理端口
- 尝试使用不同的浏览器测试
使用多个代理
Section titled “使用多个代理”# 为不同域名使用不同代理forward-socks5 .github.com 127.0.0.1:1080 .forward-socks5 .google.com 127.0.0.1:1081 .排除特定域名
Section titled “排除特定域名”# 不代理特定域名forward-socks5 .local 127.0.0.1:1080 .