曲径通幽论坛

标题: tinyproxy 配置详解 [打印本页]

作者: beyes    时间: 2015-7-15 17:43
标题: tinyproxy 配置详解
tinyproxy 作为一个无缓存的代理服务器,便利之处在于轻巧,且能满足一眼应用要求。它虽然也具有一定的过滤功能,但终究比不上一些更专业的软件,比如 squid,privoxy,然后者的配置复杂度很可能令人沮丧。下面简单说一下 tinyproxy 的配置。

1. 安装 tinyproxy
  1. opkg update
  2. opkg install tinyproxy
复制代码

也有 luci 界面(luci-app-tinyproxy),如果需要的也可一并装上。

2. 启动 tinyproxy 很简单:
  1. uci set tinyproxy.@tinyproxy[0].enabled=1
  2. uci commit
  3. /etc/init.d/tinyproxy enable
  4. /etc/init.d/tinyproxy restart
复制代码


3. 为了方便起见,可以配置成透明代理:
  1. uci add firewall redirect
  2. uci set firewall.@redirect[0].name='Transparent Proxy Redirect'
  3. uci set firewall.@redirect[0].src=lan
  4. uci set firewall.@redirect[0].proto=tcp
  5. uci set firewall.@redirect[0].dest_port=9999
  6. uci set firewall.@redirect[0].src_dport=80
  7. uci set firewall.@redirect[0].src_dip='!192.168.1.1'
  8. uci set firewall.@redirect[0].dest_ip=192.168.1.1
  9. uci commit firewall
  10. /etc/init.d/firewall restart
复制代码

uci set firewall.@redirect[0].src_dip='!192.168.1.1' 如果你用 LUCI 界面,那么需要这一句,否则可能无法访问 LUCI 界面。如果没有这句话,tinyprox 会返回一个 400 的错误,如:
Bad Request

You tried to connect to the machine the proxy is running on

意思是,不能访问 proxy 运行所在的机器。在加上该语句之后,相当于 tinyproxy 被欺骗了,即 “客户端要访问的目标 IP 不是 192.168.1.1”,这样一来这个数据包就会被送到 tinyprox,经过代理服务器的检测没问题后(比如不含有被过滤的内容),就直接丢给路由里的 uhttpd 来处理,这样客户端就能访问到路由器的 LUCI 界面了。

在 tinyprox 中,需要开放你所在的网络使用它的服务,在配置文件中,如添加:
  1. list Allow 127.0.0.1
  2. list Allow 192.168.1.0/24
复制代码


关于日志文件位置,默认是:
option LogFile "/var/log/tinyproxy.log"

在 OpenWRT 里, /var 这个目录是在内存中的,和 /tmp 是一样的,如果你的内存比较少,那么建议使用 Syslog,比如:
  1. # Logfile "/var/log/tinyproxy.log"
  2. Syslog On
复制代码

当然你也可以弄一个计划任务,每过一定时间就清空一下日志。还可以设定日志的配置等级,如将等级设置为 Critical ,那么只要配置好,代理服务器正常运行后,应该不会看到多少这样的日志信息了:
  1. option LogLevel Critical
复制代码


为了节省系统资源,我们还可以配置下面的几个项目:
Timeout 120
MaxClients 100
MinSpareServers 5
MaxSpareServers 20
StartServers 10
MaxRequestsPerChild 10000

tinyprox 还有针对网址的过滤功能,如下配置:
option Filter "/etc/tinyproxy/filter"
option FilterURLs 1
option FilterExtended 1
option FilterCaseSensitive 0

我们指定了被过滤网址的文件,开启了 POSIX 的正则表达式,并且忽略大小写敏感。为了能够更灵活的配置过滤,建议要先熟悉一点正则表达式,比如:

启动 tinyprox 后,可以通过 ps 来检查一下是不是有进程在运行了。

最后建议,为了防止内存泄露,或者一些其他原因造成系统的性能下降,可以定期重启 tinyprox 。










欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2