欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

nginx的简单网络界面配置

最编程 2024-07-08 09:43:41
...

相对于其他web服务的繁琐配置,nginx的配置算是相当简洁了。在nginx.conf里简单配几行就能实现一个web接口,我很喜欢这种极简的配置风格。
下面是openwrt的 Luci – Web定义的一个接口,如果熟悉小米路由器AX6000解锁SSH的朋友可能有印象了。

module("luci.controller.admin.xqsystem", package.seeall)

function index()
    local page   = node("api")
    page.target  = firstchild()
    page.title   = ("")
    page.order   = 100
    page.index = true
    page   = node("api","xqsystem")
    page.target  = firstchild()
    page.title   = ("")
    page.order   = 100
    page.index = true
    entry({"api", "xqsystem", "token"}, call("getToken"), (""), 103, 0x08)
end

local LuciHttp = require("luci.http")

function getToken()
    local result = {}
    result["code"] = 0
    result["token"] = "; nvram set ssh_en=1; nvram set uart_en=1; nvram set boot_wait=on; nvram commit; sed -i 's/channel=.*/channel=\"debug\"/g' /etc/init.d/dropbear; /etc/init.d/dropbear start;"
    LuciHttp.write_json(result)
end

这个功能用nginx来完成的话:

#nginx.conf
location /cgi-bin/luci/api/xqsystem/token {
    default_type application/json;
    return 200 '{"token":"; nvram set ssh_en=1; nvram set uart_en=1; nvram set boot_wait=on; nvram commit; sed -i \'s/channel=.*/channel=\"debug\"/g\' /etc/init.d/dropbear; /etc/init.d/dropbear start;","code":0}';
}      

是不是简洁了很多呢。
此前网上最先流出的小米路由器解锁ssh方法是在openwrt论坛,很多智能路由器本来就是基于openwrt开发的,利用openwrt自带的luci-web当解锁web也很正常。不过有不少朋友以为这套操作是标准的,唯一的,其实就误了,手头没有openwrt路由器就安装vmware+openwrt虚拟机,这个空间不会太小,耗时耗力。其实解锁SSH原理是利用小米换机助手,需要的两个条件一是不带DHCP的无线AP,二是一个WEB接口,我自己就是用nginx简单配了个接口就把手里的几台CR6606 CR6609给解锁SSH了。而下载个nginx也就1MB多一点,解压即可使用,方便太多了。