openwrt 的nginx

简介:#

openwrt内部使用 uHTTPd来进行web服务,轻量,简单。

但是有一些静态页面,能否也放进openwrt来跑呢?

nginx由于性能和内存处理等方面的优势,也是可以在openwrt上运行的。

那就在openwrt上用nginx替代 uHTTPd,来提供web服务吧。

一:将luci放进nginx#

https://openwrt.org/docs/guide-user/luci/luci.essentials#configuration

LuCI on nginx#

For routers without significant space constraints running on snapshots/master or v19 or later, it is possible to install using nginx. LuCI on nginx is currently supported by using uwsgi as plain-cgi interpreter. You need to install one of this 2 variants of the LuCI meta-package:

  • luci-nginx - Autoinstall nginx, uwsgi-cgi and the default config file to make luci work on nginx.
  • luci-ssl-nginx - Autoinstall nginx-ssl, uwsgi-cgi and the default config file to make luci wok on nginx.

看来已经有自动化的包来实现了,也可以带SSL。

opkg update && opkg install ****即可

二:验证#

系统-启动项

uhttpd已经禁用了

nginx已启动

可以确认已经安装好了

三:查找nginx配置文件#

linux就这点不好,配置文件到处丢,不同的版本编译出来,配置文件位置也不同。

nginx -t -c /etc/nginx/uci.conf   #测试配置文件

nginx -T -c /etc/nginx/uci.conf   #详细测试配置文件

 

具体看配置文件当中有

include conf.d/*.conf;

那么我们就自己新建配置文件吧

四:新建端口监听#

先搞用端口的,有空再搞按域名的。

/etc/nginx/conf.d  目录下新建subweb.conf

内容如下:

 

1
2
3
4
server {
        listen 10088;
        listen [::]:10088;
    }

/etc/init.d/nginx reload  #重新读取配置

/etc/init.d/nginx restart   #重启nginx服务

netstat -anutp |grep 10088  #查看10088端口监听

 

 端口已经监听了

五:完整配置#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
server {
        listen 10088;
        listen [::]:10088;
        server_name  _;
        charset utf-8;
        location / {
            root /storage/data/share;
            index index.html;
            autoindex on;
            autoindex_exact_size off;
            autoindex_localtime on;
            add_header Cache-Control no-store;
            }
        }

  

这个是配置文件浏览/storage/data/share目录

六:继续添加两个新项目#

订阅转换,订阅模板

八:特殊端口#

虽然你可以开放10080端口,但是现在的主流浏览器都默认禁止访问10080端口了。

IPV4的80 443 1080 运营商都封过了。

九:nginx默认白名单#

/etc/nginx/restrict_locally

这个文件是nginx的默认白名单,出现403错误的时候,记得配一下吧。

复制代码
    allow ::1;
    allow fc00::/7;
    allow fec0::/10;
    allow fe80::/10;
    allow 127.0.0.0/8;
    allow 10.0.0.0/8;
    allow 172.16.0.0/12;
    allow 192.168.0.0/16;
    allow 169.254.0.0/16;
    allow 2408::/10; #我加的
    allow 2409::/10; #我加的
    allow 240e::/10; #我加的
    deny all;
复制代码

 

  

十:openwrt防火墙#

记得打开openwrt的防火墙,自己创建规则,允许WAN访问这个端口,否则外部无法访问。

  

 

作者:上官飞鸿

出处:https://www.cnblogs.com/jackadam/p/16012498.html

版权:本作品采用「知识共享-署名-非商业性-禁止演绎(CC-BY-NC-ND)」许可协议进行许可。

posted @   上官飞鸿  阅读(20552)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
more_horiz
keyboard_arrow_up light_mode palette
选择主题
menu
点击右上角即可分享
微信分享提示