mod-http-lua

 

 


Install on U22

 

 

add-apt-repository ppa:ondrej/nginx

apt update

apt install libnginx-mod-http-lua

10-mod-http-ndk.conf -> /usr/share/nginx/modules-available/mod-http-ndk.conf

50-mod-http-lua.conf -> /usr/share/nginx/modules-available/mod-http-lua.conf

 


Run lua file

 

content_by_lua_block

location /lua_content {
    default_type 'text/plain';
    content_by_lua_block {
        ngx.say('Hello, world!')
    }
}

將 code 放在 file (content_by_lua_file)

content_by_lua_file /home/lua_scripts/content.lua;

 * 修改 .lua 檔後不用 reload nginx

 


Variables

 

URL Variables

cur url/test?a=hello,world

ngx.say(ngx.var.arg_a)

Nginx variables

 

ngx.ctx.X

e.g.

ngx.say(ngx.var.remote_addr)

 


Run Shell Script

 

content.lua

os.execute("/home/lua_scripts/run.sh")

run.sh

#!/bin/bash
echo test1
echo $(id) > /home/lua_scripts/test.txt

cat test.txt

uid=33(www-data) gid=33(www-data) groups=33(www-data)

 


 

 

 

 

Creative Commons license icon Creative Commons license icon