Squid
Squid 是一个常用的开源代理服务器,适合用于缓存和内容过滤。
安装 Squid
通过 OpenWrt 的包管理器安装:
opkg update
opkg install squid
配置 Squid
编辑配置文件:
vi /etc/squid/squid.conf
http_proxy 127...1:3128
http_cache_size 32MB
启动服务:
service squid restart
Nginx
Nginx 是一个高性能的网服务器,常用于反向代理和负载均衡。
安装 Nginx
opkg update
opkg install nginx
配置 Nginx
创建配置文件:
vi /etc/nginx/nginx.conf
events { worker_connections 1024; }
server {
listen 80;
server_name 127...1;
location / {
proxy_pass http://127...1:3128;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
启动服务:
nginx -c /etc/nginx/nginx.conf
Apache
Apache 是另一个常用的代理服务器,但在 OpenWrt 中可能不如 Nginx 常用。
安装 Apache
opkg update
opkg install apache2
配置 Apache
创建配置文件:
vi /etc/apache2/sites-enabled/000-default.conf
Listen 80
NameVirtualHost 127...1:80
ProxyPreserveHost On
ProxyPass / http://127...1:3128/
启动服务:
/etc/init.d/apache2 start
Luci
OpenWrt 提供了一个基于 web 界面的配置工具 Luci,适合简单的代理配置。
进入 Luci
通过浏览器访问路由器的管理地址,进入 Luci界面。
配置代理
在 Luci 中,进入“网络” -> “防火墙” -> “NAT”,添加端口转发规则,确保代理流量可以通过。
Privoxy
Privoxy 是一个轻量级的代理服务器,适合需要简单代理功能的场景。
安装 Privoxy
opkg update
opkg install privoxy
配置 Privoxy
创建配置文件:
vi /etc/privoxy/privoxy.conf
listen 127...1
listenport 8888
forward 127...1:3128 .
启动服务:
privoxy -F /etc/privoxy/privoxy.conf
自定义脚本
如果有特定的需求,可以编写 shell 脚本来自动配置代理。
注意事项
- 防火墙设置:确保代理服务器的端口(如 3128)在防火墙允许列表中。
- 证书管理:如果需要 HTTPS代理,可能需要配置证书。
- 性能优化:根据流量量调整缓存大小和其他性能参数。
通过以上方法,你可以根据需求选择合适的代理工具,并在 OpenWrt 中顺利配置。









