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

相关推荐
咚为6 小时前
比AccessLog更全面的原生Nginx 日志记录
运维·nginx·junit
xiufeia4 天前
后端项目初始化的一些小坑点
java·junit·maven·idea
Kiyra5 天前
Query Rewrite 不是越智能越好:RAG 检索的精确词保护与动态召回
redis·websocket·junit·单元测试·json
weixin_408099677 天前
触动精灵调用身份证OCR识别API实现智能信息录入(Lua脚本实战)
junit·ocr·lua·自动化脚本·石榴智能·身份证ocr识别·触动精灵
ppandss19 天前
JavaWeb从0到1-DAY5.1-Maven-JUnit
junit·log4j·maven
上海合宙LuatOS9 天前
Air780EPM通过MQTT上传温湿度数据
开发语言·人工智能·物联网·junit·luatos
傻瓜搬砖人13 天前
SpringBoot整合Junit-Redis-打包
spring boot·redis·junit
lohiecan14 天前
国产自研开源新语言|梦丘 MOS-LANG 重磅登场!深耕 AI 编程与嵌入式生态
人工智能·junit
chxii15 天前
lua流程控制语句和table(表)数据结构
开发语言·junit·lua
Dylan的码园16 天前
Maven基础架构与整体认识
java·junit·maven