Blame
| 953a52 | Qwas | 2024-10-31 15:02:36 | 1 | # OpenWrt 使用 Nginx |
| 2 | ||||
| 3 | 由于 OpenWrt 默认使用了 uhttpd,占据了 Web 端口 uhttpd 可以执行 luci 的 cgi 文件(路由器管理界面),但 Nginx 不行。 |
|||
| 4 | ||||
| 5 | ## 修改 uhttpd 配置 |
|||
| 6 | ||||
| 7 | ```sh |
|||
| 8 | vi /etc/config/uhttpd |
|||
| 9 | ``` |
|||
| 10 | ||||
| 11 | 修改 listen 的端口,把 `80` 端口改成 `81`,把 `443` 端口修改 `1443` |
|||
| 12 | ||||
| 13 | 重启 uhttpd |
|||
| 14 | ||||
| 15 | ```sh |
|||
| 16 | service uhttpd restart |
|||
| 17 | ``` |
|||
| 18 | ||||
| 19 | ## 安装 nginx |
|||
| 20 | ||||
| 21 | ```sh |
|||
| 22 | opkg update |
|||
| 23 | opkg install nginx |
|||
| 24 | ``` |
|||
| 25 | ||||
| 26 | ## 禁用 uci 配置 nginx |
|||
| 27 | ||||
| 28 | > uci 会根据按 uci 配置,生成 nginx 文件,默认配置会将 http 重定向到 https |
|||
| 29 | > |
|||
| 30 | > 这里禁用uci,选择自行编写 nginx 配置 |
|||
| 31 | ||||
| 32 | ```sh |
|||
| 33 | uci set nginx.global.uci_enable=false |
|||
| 34 | uci commit nginx |
|||
| 35 | ``` |
|||
| 36 | ||||
| 37 | ## 添加 nginx 配置文件 |
|||
| 38 | ||||
| 39 | ```sh |
|||
| 40 | vi /etc/nginx/conf.d/_lan.conf |
|||
| 41 | ``` |
|||
| 42 | ||||
| 43 | ```conf |
|||
| 44 | server { |
|||
| 45 | listen 80; |
|||
| 46 | server_name _; |
|||
| 47 | location / { |
|||
| 48 | proxy_pass http://127.0.0.1:81; |
|||
| 49 | } |
|||
| 50 | } |
|||
| 51 | ``` |
|||
| 52 | ||||
| 53 | ```sh |
|||
| 54 | service nginx reload |
|||
| 55 | service nginx restart |
|||
| 56 | ``` |