A simple example of Hello world written by openresty server using Lua script

Time:2022-5-10

Openresty provides rich interfaces and variables to Lua. Developers can make full use of Lua language features and these interfaces for efficient development. Everything is difficult at the beginning, but for programming, being able to write Hello world is half the success.

1. Install openresty

2. Configure nginx

 

Copy codeThe code is as follows:

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. New / opt / Lua / bin / test lua

 

 

Copy codeThe code is as follows:

local welcome = ‘Hello World’
ngx.say(welcome)

4. Just visit

 

A simple example of Hello world written by openresty server using Lua script