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多一点,解压即可使用,方便太多了。
推荐阅读
-
安装 Prometheus 和 Grafana,通过简单配置和使用 PromQL 查询语言以及基于 Pushgateway 的 Prometheus 数据收集,实现监控数据的可视化。
-
Nginx 配置 MinIO 访问指南:从单机到集群的最佳实践
-
一个简单的网络摄像头应用程序 6
-
限制访问和加强安全性的NGINX配置指南
-
Nginx配置:探索与这个开源服务器相关的设置
-
使用不同的 root 配置nginx多个location
-
CentOS 7安装ipvsadm和Nginx,并进行基本配置与测试 下面是重写后的段落: 1. 关闭防火墙 2. 在浏览器中输入服务器IP地址并访问 3. 修改网页内容以区分不同的服务器 4. 配置lvs/nat,使用自定义的脚本 5. 检查ipvsadm设置的规则 6. 关闭防火墙 7. 测试LVS效果。
-
简单易懂!一步步教你如何在LNMP环境中安装Nginx、进行测试并配置域名
-
简单易懂!LNMP环境的安装和配置指南
-
CentOS 7系统下,使用jemalloc优化Nginx和MySQL的LNMP配置