Lua > OpenResty Lua Module
Lua > OpenResty Lua Module
参考 https://www.bilibili.com/video/BV1k54y1z7L5/
mkdir hello
cd hello
mkdir conf logs lua
vim lua/hello.lua
vim conf/nginx.conf
lua/hello.lua
local _M = {}function _M.greet(name)ngx.say("Hello ", name)
endreturn _M
conf/nginx.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")}}}
}
tree
.
├── conf
│ └── nginx.conf
└── logs
nginx -p ./ -t
nginx -p ./
ps aux | grep nginx
curl 'http://127.0.0.1:8888'
Hello World