openresty(二)使用lua開發

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;
        }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章