1.簡述
在openresty中使用lua開發
2.直接使用content_by_lua響應
在/usr/local/openresty/nginx/conf/nginx.conf
,修改文件配置,把下面的添加到要訪問的location中
default_type text/html;
content_by_lua '
ngx.say("<p>Hello, World!</p>")
';
添加之後就和下面一樣了
location / {
# root html;
# index index.html index.htm;
default_type text/html;
content_by_lua '
ngx.say("<p>Hello, World!</p>")
';
}
3.使用content_by_lua_file引入lua腳本文件
如果lua腳本行數寫的太多,使用content_by_lua_file引入lua文件,便於維護,路徑基於/usr/local/openresty/nginx目錄下
content_by_lua_file lua
location / {
# root html;
# index index.html index.htm;
default_type text/html;
content_by_lua_file lua/test.lua;
}