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

相关推荐
金銀銅鐵3 天前
浅解 JUnit 4 第十一篇:@Before 注解和 @After 注解如何发挥作用?
junit·单元测试
金銀銅鐵4 天前
浅解 JUnit 4 第十篇:方法上的 @Ignore 注解
junit·单元测试
金銀銅鐵8 天前
浅解 JUnit 4 第九篇:JUnitCore (下)
junit·单元测试
钟智强8 天前
CVE-2025-49844高危预警:Redis Lua脚本引擎UAF漏洞深度剖析与POC实战
数据库·redis·web安全·junit·lua
金銀銅鐵9 天前
浅解 JUnit 4 第八篇:JUnitCore (上)
junit·单元测试
百锦再11 天前
Java中的日期时间API详解:从Date、Calendar到现代时间体系
java·开发语言·spring boot·struts·spring cloud·junit·kafka
金銀銅鐵12 天前
浅解 Junit 4 第七篇:AllDefaultPossibilitiesBuilder
java·junit·单元测试
金銀銅鐵13 天前
浅解 Junit 4 第六篇:AnnotatedBuilder 和 RunnerBuilder
后端·junit·单元测试
金銀銅鐵14 天前
浅解 Junit 4 第五篇:IgnoredBuilder 和 RunnerBuilder
junit·单元测试
金銀銅鐵17 天前
浅解 Junit 4 第四篇:类上的 @Ignore 注解
java·junit·单元测试