前言
在使用 openwrt 系统的时候,会有很多不同的服务端口,每次都要打开管理平台然后跳转,很麻烦,这时候如果管理站点打开就可以选择服务端口并且跳转,那就很方便了。
制作项目
采用 React 做前端,node 做后端的前后端分离架构
前端
AI 生成的前端项目
后端
AI 生成的后端项目
node服务端准备
确认架构
用于确定可用的 node 版本
[root@sjmy:05:43 PM /www] # cat /etc/os-releaseNAME="Kwrt"VERSION="25.12-SNAPSHOT"ID="kwrt"ID_LIKE="lede openwrt"PRETTY_NAME="Kwrt 25.12-SNAPSHOT"VERSION_ID="25.12-snapshot"HOME_URL="https://openwrt.ai/"BUG_URL="https://bugs.openwrt.org/"SUPPORT_URL="https://forum.openwrt.org/"FIRMWARE_URL="https://downloads.openwrt.org/"BUILD_ID="01.26.2026"OPENWRT_BOARD="mediatek/filogic"OPENWRT_ARCH="aarch64_cortex-a53"OPENWRT_TAINTS="busybox"OPENWRT_DEVICE_MANUFACTURER="Kiddin'"OPENWRT_DEVICE_MANUFACTURER_URL="https://openwrt.org/"OPENWRT_DEVICE_PRODUCT="Generic"OPENWRT_DEVICE_REVISION="v0"OPENWRT_RELEASE="Kwrt 25.12-SNAPSHOT 01.26.2026 by Kiddin'"OPENWRT_BUILD_DATE="1769290736"[root@sjmy:05:43 PM /www] # uname -maarch64综合以上的系统架构,还有我本地的我决定安装 v22.13.1 版本的 node 确认剩余空间,用于决定安装位置
[root@sjmy:05:43 PM /www] # df -hFilesystem Size Used Available Use% Mounted on/dev/root 53.5M 53.5M 0 100% /romtmpfs 489.8M 2.8M 487.0M 1% /tmp/dev/loop0 1.9G 288.0M 1.6G 15% /overlayoverlayfs:/overlay 1.9G 288.0M 1.6G 15% /tmpfs 512.0K 0 512.0K 0% /dev/dev/mmcblk0p6 54.4G 1.3G 50.4G 2% /mnt/mmcblk0p6看上面我的是 /mnt/mmcblk0p6 剩余 50.4G ,综合 node 版本,所以我打算安装在 /mnt/mmcblk0p6/node22
下载 node
cd /mnt/mmcblk0p6wget https://mirrors.tuna.tsinghua.edu.cn/nodejs-release/v22.13.1/node-v22.13.1-linux-arm64.tar.xz[root@sjmy:10:47 PM /www] # cd /mnt/mmcblk0p6[root@sjmy:10:47 PM /mnt/mmcblk0p6] # wget https://mirrors.tuna.tsinghua.edu.cn/nodejs-release/v22.13.1/node-v22.13.1-linux-arm64.tar.xz--2026-02-15 22:47:21-- https://mirrors.tuna.tsinghua.edu.cn/nodejs-release/v22.13.1/node-v22.13.1-linux-arm64.tar.xzResolving nodejs.org... 172.66.128.70, 104.20.1.252, 2606:4700:10::6814:1fc, ...Connecting to nodejs.org|172.66.128.70|:443... connected.HTTP request sent, awaiting response... 200 OKLength: 28636608 (27M) [application/x-xz]Saving to: 'node-v22.13.1-linux-arm64.tar.xz'
node-v22.13.1-linux-arm64.tar.xz 100%[=============================================================================>] 27.31M 17.9KB/s in 17m 7s
2026-02-15 23:04:30 (27.2 KB/s) - 'node-v22.13.1-linux-arm64.tar.xz' saved [28636608/28636608]只要有最后一行这个saved就意味着下载完成了
解压 node
tar -xf node-v22.13.1-linux-arm64.tar.xzmv node-v22.13.1-linux-arm64 node22rm node-v22.13.1-linux-arm64.tar.xz[root@sjmy:11:15 PM /mnt/mmcblk0p6] # tar -xf node-v22.13.1-linux-arm64.tar.xz[root@sjmy:11:15 PM /mnt/mmcblk0p6] # mv node-v22.13.1-linux-arm64 node22[root@sjmy:11:15 PM /mnt/mmcblk0p6] # rm node-v22.13.1-linux-arm64.tar.xz检测是否解压成功
[root@sjmy:11:24 PM /mnt/mmcblk0p6] # ls ./node22/bincorepack node npm npx将 node 添加到 Path
方案一
- 编辑文件
/etc/profile- 在文件中添加以下内容:
export PATH=$PATH:/mnt/mmcblk0p6/node22/bin方案二
由于我的/etc/profile文件里面有下面这一段
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
if [ -z "$FAILSAFE" ] ; then for FILE in /etc/profile.d/*.sh ; do [ -f "${FILE%.sh}.hush" ] && continue if [ "$FILE" == "/etc/profile.d/30-sysinfo.sh" ]; then [ "$(which bash)" ] && env -i bash "$FILE" else [ -f "$FILE" ] && . "$FILE" fi done unset FILEfi由于上面的 PATH 已经被重新定义了,所以我不能像上面那样直接添加一行信息在文件里面,但是由于下面的这个逻辑我可以在/etc/profile.d/目录下添加一个 sh 文件,因为这个逻辑就是把/etc/profile.d/*.sh加载进来
- 创建 profile 文件
vi /etc/profile.d/node.sh- 写入:
#!/bin/shexport PATH=/mnt/mmcblk0p6/node22/bin:$PATH保存。 3. 赋予权限
chmod +x /etc/profile.d/node.sh- 刷新
source /etc/profile- 测试
node -v很不巧,我的服务器端不支持 node
我现在的架构是:浏览器 -> nginx -> uwsgi -> LuCI (Lua)
后端配置
| 方案 | 是否推荐 | 原因 |
|---|---|---|
| Node | ❌ | musl 不兼容 glibc |
| Python | ⚠ | 占用较高,需要常驻进程 |
| CGI | ❌ | 你没有 uhttpd |
| Lua Controller | ✅ | 原生支持,最低占用 |
环境说明:
-
OpenWRT (musl libc)
-
nginx + uwsgi + LuCI
-
不使用 Node
-
不使用 Python
-
后端必须使用 Lua
-
必须使用 LuCI Controller 模式
-
数据库存储使用 SQLite
-
数据库文件路径:/mnt/mmcblk0p6/db/data.db(可以随意发挥,只要在 db 目录下都行)
-
API 返回 JSON
后端服务部署
因为一般我觉得在 mac 上面运行一个这东西还需要安装环境,有点大材小用了,所以我就直接在路由器端进行部署了。
- 将 routerlist.lua 复制到 /usr/lib/lua/luci/controller/routerlist.lua
- 将 db.lua 复制到 /usr/lib/lua/luci/model/routerlist/db.lua
- 确保安装依赖包:
- luasql-sqlite3
- luci-lib-jsonc
- 数据库位置固定为 /mnt/mmcblk0p6/db/data.db ,首次访问会自动建表并初始化默认密码为 1
nginx 配置
由于kwrt 系统 nginx 都是用的 uci 管理 ,不能直接修改/etc/nginx/uci.conf,需要在/etc/nginx/conf.d/下创建*.locations文件
1. 创建locations文件
在你的路由器上执行:
vi /etc/nginx/conf.d/routerlist.locations2. 写入以下配置
location /main { alias /www/routerlist; try_files $uri $uri/ =404; index index.html;}
location /routerlist/api/ { rewrite ^/routerlist/api/(.*)$ /cgi-bin/luci/routerlist/api/$1 break;
include uwsgi_params; uwsgi_pass unix:/var/run/luci-webui.socket; uwsgi_modifier1 9;}下面的这个/routerlist/api/可配可不配,我配了是因为我感觉原本那种太长了,所以我就 给配置了一下,然后我项目里面也改成短的了,长的也是能访问的。
3. 测试是否可用
nginx -t -c /etc/nginx/uci.conf# 或者nginx -t只要出现下面的ok和successful就表示成功了
nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful- 重启
/etc/init.d/nginx restart问题
/etc/nginx/nginx.conf test failed
[root@sjmy:05:21 PM ~] # nginx -t2026/02/16 17:43:02 [alert] 866#0: OPENSSL_init_ssl() failed (SSL: error:12800067:DSO support routines::could not load the shared library:filename(/usr/lib/engines-3/devcrypto.so): Error loading shared library /usr/lib/engines-3/devcrypto.so: No such file or directory error:12800067:DSO support routines::could not load the shared library error:13000084:engine routines::dso not found error:13000074:engine routines::no such engine:id=devcrypto error:13000066:engine routines::engine configuration error:section=devcrypto_sect, name=default_algorithms, value=ALL error:0700006D:configuration file routines::module initialization error:module=engines, value=engines_sect retcode=-1 )2026/02/16 17:43:02 [emerg] 866#0: open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)nginx: configuration file /etc/nginx/nginx.conf test failed这个是因为UCI 管理的 nginx 不存在/etc/nginx/nginx.conf文件,真正的配置文件是/etc/nginx/uci.conf,所以这里会找不到该文件。
解决方法:
# 创建符号链接ln -sf /etc/nginx/uci.conf /etc/nginx/nginx.conf如果这篇文章对你有帮助,欢迎分享给更多人!
部分信息可能已经过时





