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

相关推荐
zhengfei6111 天前
CVE-2025-49844 深度分析
junit
醇氧1 天前
JUnit 5的 Assertions
junit
杀死那个蝈坦1 天前
OpenResty
junit·openresty
李绍熹3 天前
Lua 语言基础教程
开发语言·junit·lua
李绍熹3 天前
Lua 错误处理详解
开发语言·junit·lua
weixin_462446233 天前
【原创实践】安装与配置 lua-cjson 在宝塔 Nginx 上
nginx·junit·lua
红石榴花生油3 天前
Lua语句与Redis方法的区别及实战笔记
junit
IMPYLH3 天前
Lua 的 select 函数
java·开发语言·笔记·后端·junit·游戏引擎·lua
旷野说3 天前
用 Redis + Lua 守住打赏原子性:我在单体系统中的微观实践(续)
redis·junit·lua
想做后端的前端3 天前
Lua基本数据类型
java·junit·lua