nginx的简单web接口配置

相对于其他web服务的繁琐配置,nginx的配置算是相当简洁了。在nginx.conf里简单配几行就能实现一个web接口,我很喜欢这种极简的配置风格。

下面是openwrt的 Luci -- Web定义的一个接口,如果熟悉小米路由器AX6000解锁SSH的朋友可能有印象了。

lua 复制代码
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来完成的话:

lua 复制代码
#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多一点,解压即可使用,方便太多了。

相关推荐
MiNG MENS18 分钟前
nginx 代理 redis
运维·redis·nginx
珊瑚怪人1 小时前
一个域名问题
nginx
dxdz4 小时前
一文搞定 Linux Nginx 从安装、启动到 nginx.conf 全配置详解(新手也能看懂)
nginx
chxii4 小时前
lua中Table 与 Metatable
lua
遇见火星4 小时前
Nginx 负载均衡配置模板:轮询、权重、IP哈希、最少连接
tcp/ip·nginx·负载均衡
untE EADO7 小时前
Nginx代理到https地址忽略证书验证配置
运维·nginx·https
xingpanvip8 小时前
星盘接口开发文档:组合三限盘接口指南
android·开发语言·前端·python·php·lua
zx2859634008 小时前
Laravel10.x重磅升级:核心特性全解析
mysql·gateway·智能路由器
Treh UNFO8 小时前
nginx的重定向
大数据·数据库·nginx
理人综艺好会9 小时前
nginx了解
运维·nginx