1.工程化的nginx+lua项目结构
hello
hello.conf
lua
hello.lua
lualib
*.lua
*.so
2.配置nginx.conf
# vi /usr/servers/nginx/conf/nginx.conf
worker_processes 2;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type text/html;
lua_package_path "/usr/servers/lualib/?.lua;;";
lua_package_cpath "/usr/servers/lualib/?.so;;";
include /usr/hello/hello.conf;
}
3.配置hello.conf
#mkdir -p /usr/hello
#vi /usr/hello/hello.conf
server {
listen 80;
server_name _;
location /lua {
default_type 'text/html';
lua_code_cache off;
content_by_lua_file /usr/hello/lua/hello.lua;
}
}
# mkdir -p /usr/hello/lua
# vi /usr/hello/lua/hello.lua
ngx.say("hello world");
4.验证配置是否正确
#/usr/servers/nginx/sbin/nginx -t
5.重新nginx加载配置
#/usr/servers/nginx/sbin/nginx -s reload
6.访问
http://192.168.135.136/lua
hello world
7.查看nginx日志
#tail -f /usr/servers/nginx/logs/access.log
#tail -f /usr/servers/nginx/logs/error.log