簡介:
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
內容如下:
server { listen 10088; listen [::]:10088; }
/etc/init.d/nginx reload #重新讀取配置
/etc/init.d/nginx restart #重啟nginx服務
netstat -anutp |grep 10088 #查看10088端口監聽
端口已經監聽了
五:完整配置
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訪問這個端口,否則外部無法訪問。