Openresty服务器使用lua脚本写的Hello World简单实例

Openresty提供了丰富的接口和变量给Lua,开发者可以充分利用Lua语言特性和这些接口进行高效率开发。万事开头难,但是对于编程来说能写出Hello world就已经算是成功一半了。

1、安装openresty

2、配置nginx

server {
     listen 80;
     server_name localhost;
 
     #charset koi8-r;
 
     #access_log logs/host.access.log main;
 
     location / {
     root html;
          index index.html index.htm;
     }
     location /lua {
          default_type text/plain;
          content_by_lua_file /opt/lua/bin/test.lua;
     }
     ........
}

3、新建 /opt/lua/bin/test.lua

local welcome = 'Hello World'
ngx.say(welcome)

4、访问即可