栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Nginx Lua 安装与配置

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Nginx Lua 安装与配置

OpenResty - 安装

Nginx 配置

    server {
        listen       90;
        server_name  localhost;

        charset utf-8;

        #access_log  logs/host.access.log  main;
        #关闭访问日志 linux
        #access_log /dev/null;
        #关闭访问日志 windows
        access_log \.\nul;
        #错误日志
        error_log  E:/nglua/demo/logs/error.log;

        location / {
            root   html;
            index  index.html index.htm;
        }

        location /test
        {
            #是否开通lua编译缓存
            lua_code_cache off;
            #根目录
            root E:/nglua/demo;
            default_type text/html;
            content_by_lua_file E:/nglua/demo/callgo.lua;
        }

LUA DEMO

--用于接收前端数据的对象
local args=nil
--获取前端的请求方式 并获取传递的参数   
local request_method = ngx.var.request_method
--判断是get请求还是post请求并分别拿出相应的数据
if "GET" == request_method then
        args = ngx.req.get_uri_args()
elseif "POST" == request_method then
        ngx.req.read_body()
        args = ngx.req.get_post_args()
        --兼容请求使用post请求,但是传参以get方式传造成的无法获取到数据的bug
        if (args == nil or args.data == null) then
                args = ngx.req.get_uri_args()
        end
end

--获取前端传递的name值
local name = args.name
--响应前端
ngx.say("hello:"..name)

浏览器

http://127.0.0.1:90/test?name=openresty

Nginx 安装成服务
下载 nssm https://nssm.cc/release/nssm-2.24.zip

nssm install nginx-lua

nssm remove nginx-la 卸载服务
nssm restart nginx-la 重启服务
nginx -s reload 重新加载配置

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/730819.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号