nginx+lua+openresty 实例
1、在http部分添加如下配置
lua模块路径,多个之间”;”分隔,其中”;;”表示默认搜索路径,默认到/usr/servers/nginx下找
lua_package_path “/usr/servers/lualib/?.lua;;”; #lua 模块
lua_package_cpath “/usr/servers/lualib/?.so;;”; #c模块
2、在nginx.conf中的http部分添加include lua.conf包含此文件片段
Java代码 收藏代码
include/usr/servers/example/lua.conf;
在/usr/server/nginx/conf下
vim lua.conf
#lua.conf
server {
listen 80;
server_name _;
location /lua {
default_type 'text/html';
content_by_lua 'ngx.say("hello world")';
}
}
将Lua项目化:
mkdir /usr/example
cp -r /usr/servers/lualib/ /usr/example/
mkdir /usr/example/lua
cd /usr/example
vim example.conf
server {
listen 80;
server_name _;
location /lua {
default_type 'text/html';
lua_code_cache off;
content_by_lua_file /usr/example/lua/test.lua;
}
}
vim /usr/example/lua/test.lua
ngx.say("hello world");
cd /usr/servers/nginx/conf/
vim nginx.conf
http模块:
http {
include mime.types;
default_type application/octet-stream;
lua_package_path "/usr/example/lualib/?.lua;;"; #lua 模块
lua_package_cpath "/usr/example/lualib/?.so;;"; #c模块
include /usr/example/example.conf;
....
....
}
nginx -s reload
浏览器访问: http://192.168.100.65/lua