Lua > OpenResty Lua Module

Lua > OpenResty Lua Module

参考 https://www.bilibili.com/video/BV1k54y1z7L5/

bash 复制代码
mkdir hello
cd hello
mkdir conf logs lua
vim lua/hello.lua
vim conf/nginx.conf

lua/hello.lua

lua 复制代码
local _M = {}

function _M.greet(name)
    ngx.say("Hello ", name)
end

return _M

conf/nginx.conf

conf 复制代码
worker_processes 1;

events {
    worker_connections 1024;
}

http {
    lua_package_path "$prefix/lua/?.lua;;";  
    server {
        listen 8888 reuseport;
        
        location / {
            default_type text/plain;
            content_by_lua_block {
                local hello = require "hello"
                hello.greet("World")
            }
        }
    }
}
bash 复制代码
tree

.

├── conf

│ └── nginx.conf

└── logs

bash 复制代码
nginx -p ./ -t
nginx -p ./
ps aux | grep nginx
curl 'http://127.0.0.1:8888'

Hello World

相关推荐
Java小白笔记3 天前
Java 单元测试怎么写:JUnit 5、Mockito 与 Spring Boot 方法级实战
java·junit·单元测试
盟道科技6 天前
Redis+Lua 实现滑动窗口限流:从固定窗口踩坑到生产可用的完整方案
redis·junit·lua
呆呆敲代码的小Y13 天前
Lua 上值(UpValue)
开发语言·junit·lua·lua上值·upvalue
呆呆敲代码的小Y13 天前
【游戏开发】xLua 性能优化技巧
junit·性能优化·lua·xlua
lhldsg17 天前
家政派单系统开发实战:从需求分析到智能调度全流程指南
java·junit·小程序·uni-app·需求分析
肠畔码农19 天前
深度解密 Redis 核心引擎:从 MULTI/EXEC 事务机制到 EVAL 脚本的原子性演进
数据库·redis·junit
会编程的吕洞宾21 天前
Spring Cloud Gateway限流:Redis令牌桶防刷实战
数据库·redis·junit
難釋懷24 天前
Nginx-Lua
nginx·junit·lua
萧瑟余晖24 天前
Java深入解析篇三十七之JUnit 5 详解
java·junit
骑士雄师1 个月前
superpowers使用流程
junit·skill