安装环境介绍
环境名称 | 版本 |
---|
linux | CentOS Linux release 7.7.1908 (Core) |
docker-ce | 19.03.8 |
docker-compose | 1.24.0-rc1 |
docker image | vimagick/privoxy:latest |
初始目录结构
1 2 3 4 5
| ~/fig/privoxy/ ├── docker-compose.yml └── privoxy/ ├── user.action └── user.filter
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| version: "3.5"
services: privoxy: image: vimagick/privoxy:latest container_name: privoxy ports: - 8118:8118 volumes: - ./privoxy/user.action:/etc/privoxy/user.action - ./privoxy/user.filter:/etc/privoxy/user.filter cap_add: - NET_ADMIN restart: always
|
- 文件:
user.action
,以下的配置内容,作用是阻止 Privoxy 指向服务器本身的 IP 和域名,需要替换为你自己服务器的 IP 和域名。
1 2 3 4
| {+block{block ip and domain which point to server itself}} 127.0.0.1 45.32.57.113 .example.com
|
- 文件:
user.filter
,该文件用于存放 Privoxy 的过滤规则,暂时不需要填写任何内容。
启动 Privoxy 服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| # cd ~/fig/privoxy/
# docker-compose up -d
$ docker-compose logs
Attaching to privoxy privoxy | 2020-03-27 22:49:28.383 7f30fa6aed48 Info: Privoxy version 3.0.28 privoxy | 2020-03-27 22:49:28.383 7f30fa6aed48 Info: Program name: privoxy privoxy | 2020-03-27 22:49:28.384 7f30fa6aed48 Info: Loading filter file: /etc/privoxy/default.filter privoxy | 2020-03-27 22:49:28.386 7f30fa6aed48 Info: Loading filter file: /etc/privoxy/user.filter privoxy | 2020-03-27 22:49:28.386 7f30fa6aed48 Info: Loading actions file: /etc/privoxy/match-all.action privoxy | 2020-03-27 22:49:28.386 7f30fa6aed48 Info: Loading actions file: /etc/privoxy/default.action privoxy | 2020-03-27 22:49:28.389 7f30fa6aed48 Info: Loading actions file: /etc/privoxy/user.action privoxy | 2020-03-27 22:49:28.389 7f30fa6aed48 Info: Listening on port 8118 on IP address 0.0.0.0
|
创建 Privoxy 的主配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| # cd ~/fig/privoxy
# docker cp privoxy:/etc/privoxy/config ./privoxy/config
# chmod 644 ./privoxy/config
# vim docker-compose.yml volumes: - ./privoxy/config:/etc/privoxy/config
# docker-compose restart
~/fig/privoxy/ ├── docker-compose.yml └── privoxy/ ├── config ├── user.action └── user.filter
|
限制访问来源(可选步骤)
Privoxy 支持 IP 白名单的功能,配置示例如下:
1 2 3 4 5 6 7 8 9
| # cd ~/fig/privoxy
# vim ./privoxy/config permit-access 14.215.177.38/26
# docker-compose restart
|
开放防火墙端口(Centos7)
1 2 3 4 5 6 7 8
| # firewall-cmd --zone=public --permanent --add-port=8118/tcp
# firewall-cmd --reload
# firewall-cmd --list-ports
|
验证代理服务是否可用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| # curl -I -x 127.0.0.1:8118 www.baidu.com
HTTP/1.1 200 OK Accept-Ranges: bytes Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform Connection: keep-alive Content-Length: 277 Content-Type: text/html Date: Fri, 27 Mar 2020 01:39:09 GMT Etag: "575e1f6f-115" Last-Modified: Mon, 13 Jun 2016 02:49:08 GMT Pragma: no-cache Server: bfe/1.0.8.18 Proxy-Connection: keep-alive
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| # curl -I -x 45.32.57.113:8118 www.baidu.com HTTP/1.1 200 OK Accept-Ranges: bytes Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform Connection: keep-alive Content-Length: 277 Content-Type: text/html Date: Fri, 27 Mar 2020 01:40:09 GMT Etag: "575e1f60-115" Last-Modified: Mon, 13 Jun 2016 02:50:08 GMT Pragma: no-cache Server: bfe/1.0.8.18 Proxy-Connection: keep-alive
|
常见问题
Privoxy 拒绝连接
Privoxy 默认绑定的地址 127.0.0.1:8118
,如果主机的 hostname
不是 localhost
或者 127.0.0.1
,则需要更改 Privoxy 的主配置文件,重新配置 listen-address
参数。
1 2 3 4
| # vim /etc/privoxy/config
listen-address yourHostName:8118
|
1
| # curl -I -x yourHostName:8118 www.baidu.com
|
参考资料