OpenWrt 使用 Nginx

由于 OpenWrt 默认使用了 uhttpd,占据了 Web 端口 uhttpd 可以执行 luci 的 cgi 文件(路由器管理界面),但 Nginx 不行。

修改 uhttpd 配置

vi /etc/config/uhttpd

修改 listen 的端口,把 80 端口改成 81,把 443 端口修改 1443

重启 uhttpd

service uhttpd restart

安装 nginx

opkg update
opkg install nginx

禁用 uci 配置 nginx

uci 会根据按 uci 配置,生成 nginx 文件,默认配置会将 http 重定向到 https

这里禁用uci,选择自行编写 nginx 配置

uci set nginx.global.uci_enable=false
uci commit nginx

添加 nginx 配置文件

vi /etc/nginx/conf.d/_lan.conf
conf
server {
  listen       80;
  server_name  _;
  location / {
    proxy_pass  http://127.0.0.1:81;
  }
}
service nginx reload
service nginx restart
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9