Lua > OpenResty Lua Module
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