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多一点,解压即可使用,方便太多了。

相关推荐
古希腊数通小白(ip在学)2 小时前
stp拓扑变化分类
运维·服务器·网络·智能路由器
Muisti11 小时前
NAT技术(网络地址转换)
网络·计算机网络·智能路由器
hrrrrb12 小时前
【TCP/IP】7. IP 路由
网络·tcp/ip·智能路由器
果子⌂13 小时前
Docker-构建镜像并实现LNMP架构
mysql·nginx·docker·容器·架构·php
江西省遂川县常驻深圳大使17 小时前
小米路由器3C刷OpenWrt,更换系统/变砖恢复 指南
智能路由器·openwrt·小米路由器
YC运维17 小时前
OSPF实验以及核心原理全解
运维·网络·网络协议·智能路由器
uuu_柚子17 小时前
IPv4和IPv6双栈配置
网络·智能路由器
喜欢你,还有大家17 小时前
实训八——路由器与交换机与网线
网络·智能路由器
YC运维1 天前
RIP实验以及核心原理
运维·网络·智能路由器
WZF-Sang1 天前
计算机网络基础——1
网络·c++·git·学习·计算机网络·智能路由器