Join the community today
Become a Member

Beta Branch Centmin Mod Nginx + Lua + LuaJIT support preview / discussions

Discussion in 'Beta release code' started by eva2000, May 27, 2015.

  1. eva2000

    eva2000 Administrator Staff Member

    53,209
    12,113
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,649
    Local Time:
    9:02 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Thinking of adding optional support for Openresty's Nginx Lua and LuaJIT modules - HttpLuaModule - Nginx Community


    See example at Pushing Nginx to its limit with Lua

    However, I am not familiar with Lua and usage cases aren't as detailed online. So any user here actually uses Lua/LuaJIT with Nginx on other platforms ? If so any simple usage example cases I can look at that you use as well so I can confirm what I install for Centmin Mod Nginx works as intended ?

    It's optional so you can disable it via ORESTY_LUANGINX='n' in centmin.sh if you have no use for it

    Code:
    ORESTY_LUANGINX='y'          # enable or disable or ORESTY_LUA* nginx modules below
    ORESTY_LUANGINXVER='0.9.16rc1'  # openresty lua-nginx-module https://github.com/openresty/lua-nginx-module
    ORESTY_LUAGITVER='2.0.4'        # luagit http://luajit.org/
    ORESTY_LUAMEMCACHEDVER='0.13'   # openresty https://github.com/openresty/lua-resty-memcached
    ORESTY_LUAMYSQLVER='0.15'       # openresty https://github.com/openresty/lua-resty-mysql
    ORESTY_LUAREDISVER='0.20'       # openresty https://github.com/openresty/lua-resty-redis
    ORESTY_LUADNSVER='0.14'         # openresty https://github.com/openresty/lua-resty-dns
    ORESTY_LUAUPLOADVER='0.09'      # openresty https://github.com/openresty/lua-resty-upload
    ORESTY_LUAWEBSOCKETVER='0.05'   # openresty https://github.com/openresty/lua-resty-websocket
    ORESTY_LUALOCKVER='0.04'        # openresty https://github.com/openresty/lua-resty-lock
    ORESTY_LUASTRINGVER='0.09'      # openresty https://github.com/openresty/lua-resty-string
    ORESTY_LUAREDISPARSERVER='0.10'    # openresty https://github.com/openresty/lua-redis-parser
    ORESTY_LUAUPSTREAMCHECKVER='0.03'  # openresty https://github.com/openresty/lua-resty-upstream-healthcheck
    ORESTY_LUALRUCACHEVER='0.04'       # openresty https://github.com/openresty/lua-resty-lrucache
    ORESTY_LUARESTYCOREVER='0.1.0'     # openresty https://github.com/openresty/lua-resty-core
    ORESTY_LUAUPSTREAMVER='0.02'       # openresty https://github.com/openresty/lua-upstream-nginx-module
    ORESTY_LUALOGGERSOCKETVER='0.1'    # cloudflare openresty https://github.com/cloudflare/lua-resty-logger-socket
    ORESTY_LUACOOKIEVER='master'       # cloudflare openresty https://github.com/cloudflare/lua-resty-cookie
    ORESTY_LUAUPSTREAMCACHEVER='0.1.1' # cloudflare openresty https://github.com/cloudflare/lua-upstream-cache-nginx-module
    
    checking if luaJIT installed in vhost.conf add to server{} context
    Code:
    location = /lua {
        default_type text/plain;
        content_by_lua '
            if jit then
                ngx.say(jit.version)
            else
                ngx.say("Not LuaJIT!")
            end
        ';
    }
    save vhost.conf and restart nginx server and access hostname/lua will give
    Code:
    LuaJIT 2.0.4
    and the lua external libs
    Code:
    ls -lah /usr/local/lib/lua/resty/
    total 328K
    drwxr-xr-x 2 root root 4.0K May 25 02:34 .
    drwxr-xr-x 4 root root   28 May 25 00:12 ..
    -rwxr-xr-x 1 root root 6.2K May 25 02:34 aes.lua
    -rwxr-xr-x 1 root root 1.9K May 25 02:34 base64.lua
    -rwxr-xr-x 1 root root 3.5K May 25 02:34 base.lua
    -rwxr-xr-x 1 root root 7.8K May 25 02:34 client.lua
    -rwxrwxr-x 1 root root 5.2K Jan  8 16:50 cookie.lua
    -rwxr-xr-x 1 root root  472 May 25 02:34 core.lua
    -rwxr-xr-x 1 root root 1.9K May 25 02:34 ctx.lua
    -rwxr-xr-x 1 root root 1.1K May 25 02:34 exit.lua
    -rwxr-xr-x 1 root root 1.9K May 25 02:34 hash.lua
    -rwxr-xr-x 1 root root  18K May 25 02:34 healthcheck.lua
    -rwxr-xr-x 1 root root 4.4K May 25 02:34 lock.lua
    -rwxr-xr-x 1 root root 4.6K May 25 02:34 lrucache.lua
    -rwxr-xr-x 1 root root 1.2K May 25 02:34 md5.lua
    -rwxr-xr-x 1 root root  15K May 25 02:34 memcached.lua
    -rwxr-xr-x 1 root root 3.1K May 25 02:34 misc.lua
    -rwxr-xr-x 1 root root  20K May 25 02:34 mysql.lua
    -rwxr-xr-x 1 root root 8.5K May 25 02:34 protocol.lua
    -rwxr-xr-x 1 root root  17K May 25 02:34 pureffi.lua
    -rwxr-xr-x 1 root root  612 May 25 02:34 random.lua
    -rwxr-xr-x 1 root root  11K May 25 02:34 redis.lua
    -rwxr-xr-x 1 root root  23K May 25 02:34 regex.lua
    -rwxr-xr-x 1 root root 8.5K May 25 02:34 request.lua
    -rwxr-xr-x 1 root root  19K May 25 02:34 resolver.lua
    -rwxr-xr-x 1 root root 4.1K May 25 02:34 response.lua
    -rwxr-xr-x 1 root root 4.8K May 25 02:34 server.lua
    -rwxr-xr-x 1 root root 1.2K May 25 02:34 sha1.lua
    -rwxr-xr-x 1 root root 1.1K May 25 02:34 sha224.lua
    -rwxr-xr-x 1 root root 1.3K May 25 02:34 sha256.lua
    -rwxr-xr-x 1 root root 1.1K May 25 02:34 sha384.lua
    -rwxr-xr-x 1 root root 1.4K May 25 02:34 sha512.lua
    -rwxr-xr-x 1 root root  236 May 25 02:34 sha.lua
    -rwxr-xr-x 1 root root 9.1K May 25 02:34 shdict.lua
    -rwxrwxr-x 1 root root  12K Feb  9 22:52 socket.lua
    -rwxr-xr-x 1 root root  694 May 25 02:34 string.lua
    -rwxr-xr-x 1 root root  436 May 25 02:34 time.lua
    -rwxr-xr-x 1 root root 5.1K May 25 02:34 upload.lua
    -rwxr-xr-x 1 root root 1.7K May 25 02:34 uri.lua
    -rwxr-xr-x 1 root root 3.0K May 25 02:34 var.lua
    -rwxr-xr-x 1 root root  445 May 25 02:34 worker.lua
    
    Nginx Lua Youtube video by Yichun Zhang at Nginx.conf 2014

    Introduction · openresty/lua-nginx-module Wiki · GitHub
    Also posted standalone Centmin Mod .08 beta 02 + lua support branch at centminmod/centminmod at 123.08lua · GitHub if anyone wants to try it out. Commit history for 123.08lua branch Commits · centminmod/centminmod · GitHub (basically all of May 25th commits)

    Centmin Mod installed for 123.08beta03 branch via Github

    Step 1.

    Select the branch you want to install from list at Branches · centminmod/centminmod · GitHub and define it in the variable named branchname typed on SSH command line as follows.
    Code:
    branchname=123.08beta03
    
    Step 2.

    Actual install
    Code:
    yum -y install wget nano bc unzip
    branchname=123.08beta03
    wget -O /usr/local/src/${branchname}.zip https://github.com/centminmod/centminmod/archive/${branchname}.zip
    cd /usr/local/src
    unzip ${branchname}.zip
    cd centminmod-${branchname}
    chmod +x centmin.sh
    
    Then to install either type

    for menu mode
    Code:
    ./centmin.sh
    
    or for CLI install mode
    Code:
    ./centmin.sh install
    
    update: Easy to try a new branch via git see Upgrade - Working with git command line for updating Centmin Mod local copies | Centmin Mod Community
     
    Last edited: May 29, 2015
  2. eva2000

    eva2000 Administrator Staff Member

    53,209
    12,113
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,649
    Local Time:
    9:02 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  3. eva2000

    eva2000 Administrator Staff Member

    53,209
    12,113
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,649
    Local Time:
    9:02 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Just updated 123.08lua branch with luajit git repository dev branch support as 2.1.0* branch has better performance than 2.0.4 stable. Also moved luajit install to dedicated inc/luajit.inc include file too.

    Commit at Add support for luajit GIT dev branch installation · centminmod/centminmod@93b45a2 · GitHub

    vhost.conf
    Code:
    location = /lua {
        default_type text/plain;
        content_by_lua '
            if jit then
                ngx.say(jit.version)
            else
                ngx.say("Not LuaJIT!")
            end
        ';
    }
    check luajit version
    Code:
    curl localhost/lua  
    LuaJIT 2.1.0-alpha
    external lua libs
    Code:
    ls -lah /usr/local/lib/lua/resty/
    total 328K
    drwxr-xr-x 2 root root 4.0K May 28 03:08 .
    drwxr-xr-x 4 root root   28 May 25 00:12 ..
    -rwxr-xr-x 1 root root 6.2K May 28 03:08 aes.lua
    -rwxr-xr-x 1 root root 1.9K May 28 03:08 base64.lua
    -rwxr-xr-x 1 root root 3.5K May 28 03:08 base.lua
    -rwxr-xr-x 1 root root 7.8K May 28 03:08 client.lua
    -rwxrwxr-x 1 root root 5.2K Jan  8 16:50 cookie.lua
    -rwxr-xr-x 1 root root  472 May 28 03:08 core.lua
    -rwxr-xr-x 1 root root 1.9K May 28 03:08 ctx.lua
    -rwxr-xr-x 1 root root 1.1K May 28 03:08 exit.lua
    -rwxr-xr-x 1 root root 1.9K May 28 03:08 hash.lua
    -rwxr-xr-x 1 root root  18K May 28 03:08 healthcheck.lua
    -rwxr-xr-x 1 root root 4.4K May 28 03:08 lock.lua
    -rwxr-xr-x 1 root root 4.6K May 28 03:08 lrucache.lua
    -rwxr-xr-x 1 root root 1.2K May 28 03:08 md5.lua
    -rwxr-xr-x 1 root root  15K May 28 03:08 memcached.lua
    -rwxr-xr-x 1 root root 3.1K May 28 03:08 misc.lua
    -rwxr-xr-x 1 root root  20K May 28 03:08 mysql.lua
    -rwxr-xr-x 1 root root 8.5K May 28 03:08 protocol.lua
    -rwxr-xr-x 1 root root  17K May 28 03:08 pureffi.lua
    -rwxr-xr-x 1 root root  612 May 28 03:08 random.lua
    -rwxr-xr-x 1 root root  11K May 28 03:08 redis.lua
    -rwxr-xr-x 1 root root  23K May 28 03:08 regex.lua
    -rwxr-xr-x 1 root root 8.5K May 28 03:08 request.lua
    -rwxr-xr-x 1 root root  19K May 28 03:08 resolver.lua
    -rwxr-xr-x 1 root root 4.1K May 28 03:08 response.lua
    -rwxr-xr-x 1 root root 4.8K May 28 03:08 server.lua
    -rwxr-xr-x 1 root root 1.2K May 28 03:08 sha1.lua
    -rwxr-xr-x 1 root root 1.1K May 28 03:08 sha224.lua
    -rwxr-xr-x 1 root root 1.3K May 28 03:08 sha256.lua
    -rwxr-xr-x 1 root root 1.1K May 28 03:08 sha384.lua
    -rwxr-xr-x 1 root root 1.4K May 28 03:08 sha512.lua
    -rwxr-xr-x 1 root root  236 May 28 03:08 sha.lua
    -rwxr-xr-x 1 root root 9.1K May 28 03:08 shdict.lua
    -rwxrwxr-x 1 root root  12K Feb  9 22:52 socket.lua
    -rwxr-xr-x 1 root root  694 May 28 03:08 string.lua
    -rwxr-xr-x 1 root root  436 May 28 03:08 time.lua
    -rwxr-xr-x 1 root root 5.1K May 28 03:08 upload.lua
    -rwxr-xr-x 1 root root 1.7K May 28 03:08 uri.lua
    -rwxr-xr-x 1 root root 3.0K May 28 03:08 var.lua
    -rwxr-xr-x 1 root root  445 May 28 03:08 worker.lua
     
  4. eva2000

    eva2000 Administrator Staff Member

    53,209
    12,113
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,649
    Local Time:
    9:02 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    split off a dedicated discussion and feedback thread for Centmin Mod's planned Nginx + Lua + LuaJIT support :)
     
  5. eva2000

    eva2000 Administrator Staff Member

    53,209
    12,113
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,649
    Local Time:
    9:02 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  6. Oxide

    Oxide Active Member

    534
    29
    28
    Mar 19, 2015
    Ratings:
    +59
    Local Time:
    9:02 AM
    Thank you so much dude, you actually listen to us :D I'm so happy that you added nginx lua!!! :Dd
     
  7. eva2000

    eva2000 Administrator Staff Member

    53,209
    12,113
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,649
    Local Time:
    9:02 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Well I only add the Nginx Lua support - how to use it and what for is up to you :)
     
  8. Oxide

    Oxide Active Member

    534
    29
    28
    Mar 19, 2015
    Ratings:
    +59
    Local Time:
    9:02 AM
    Of course, google is very helpful for that actually :)
     
  9. Cr0w

    Cr0w Member

    165
    9
    18
    Mar 17, 2015
    Iran
    Ratings:
    +13
    Local Time:
    3:32 AM
    1.9.x
    5.5
    can you tell me about luajit much more ? what is this
     
  10. eva2000

    eva2000 Administrator Staff Member

    53,209
    12,113
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,649
    Local Time:
    9:02 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  11. Oxide

    Oxide Active Member

    534
    29
    28
    Mar 19, 2015
    Ratings:
    +59
    Local Time:
    9:02 AM
    Hi,

    Lua is really light weight and can be used for many purposes where nginx rules would normally fail. You can use it for WAF (web application firewall) and even speed up your site if you use CloudFlare with it.

    Pushing Nginx to its limit with Lua
     
  12. rdan

    rdan Well-Known Member

    5,439
    1,397
    113
    May 25, 2014
    Ratings:
    +2,186
    Local Time:
    7:02 AM
    Mainline
    10.2
    This module is useless for us unless we do LUA config right?
    And to disable this, just modify ORESTY_LUANGINX='n' ?
    No need for LUAJIT_GITINSTALL='n'?
     
  13. eva2000

    eva2000 Administrator Staff Member

    53,209
    12,113
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,649
    Local Time:
    9:02 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    yeah if you have no need or use for nginx lua, then in centmin.sh set

    Code:
    LUAJIT_GITINSTALL='n'
    ORESTY_LUANGINX='n' 
    then run centmin.sh option 4 to recompile Nginx server :)
     
  14. rdan

    rdan Well-Known Member

    5,439
    1,397
    113
    May 25, 2014
    Ratings:
    +2,186
    Local Time:
    7:02 AM
    Mainline
    10.2
    I thought this is not needed to be set/modify?
    LUAJIT_GITINSTALL='n'
     
  15. eva2000

    eva2000 Administrator Staff Member

    53,209
    12,113
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,649
    Local Time:
    9:02 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    LuaJIT is only needed if Nginx LUA is enabled.. so if you have ORESTY_LUANGINX='n', you have no use for LuaJIT
     
  16. eva2000

    eva2000 Administrator Staff Member

    53,209
    12,113
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,649
    Local Time:
    9:02 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  17. eva2000

    eva2000 Administrator Staff Member

    53,209
    12,113
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,649
    Local Time:
    9:02 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Updated Centmin Mod 123.09beta01 to Nginx Lua 0.9.19 module so it now supports new block syntax

    Examples

    in vhost conf file outside of server {} context
    Code:
    lua_package_path '/usr/local/lib/lua/resty/?.lua;;';
    
    server {
    in actual vhost conf file's server {} context

    Code:
         location /lua_content {
             # MIME type determined by default_type:
             default_type 'text/plain';
    
             content_by_lua_block {
                 ngx.say('Hello,world!')
             }
         }
    
         location /nginx_var {
             # MIME type determined by default_type:
             default_type 'text/plain';
    
             # try access /nginx_var?a=hello,world
             content_by_lua_block {
                 ngx.say(ngx.var.arg_a)
             }
         }
    
        location = /lua {
            default_type text/plain;
            content_by_lua_block {
            if jit then
                ngx.say(jit.version)
            else
                ngx.say("Not LuaJIT!")
            end
            }
        }
    
    Code:
    curl localhost/lua_content
    Hello,world!
    
    curl localhost/nginx_var?a=hello
    hello
    
    curl localhost/lua           
    LuaJIT 2.1.0-beta1
    Code:
    ls -lah /usr/local/lib/lua/resty/
    total 332K
    drwxr-xr-x 2 root root 4.0K Nov 29 21:55 .
    drwxr-xr-x 4 root root 4.0K Oct 19 11:08 ..
    -rwxr-xr-x 1 root root 6.2K Nov 29 21:55 aes.lua
    -rwxr-xr-x 1 root root 3.5K Nov 29 21:55 base.lua
    -rwxr-xr-x 1 root root 1.9K Nov 29 21:55 base64.lua
    -rwxr-xr-x 1 root root 7.8K Nov 29 21:55 client.lua
    -rwxrwxr-x 1 root root 5.2K Jan  8  2015 cookie.lua
    -rwxr-xr-x 1 root root  472 Nov 29 21:55 core.lua
    -rwxr-xr-x 1 root root 1.9K Nov 29 21:55 ctx.lua
    -rwxr-xr-x 1 root root 1.1K Nov 29 21:55 exit.lua
    -rwxr-xr-x 1 root root 1.9K Nov 29 21:55 hash.lua
    -rwxr-xr-x 1 root root  18K Nov 29 21:55 healthcheck.lua
    -rwxr-xr-x 1 root root 4.4K Nov 29 21:55 lock.lua
    -rwxr-xr-x 1 root root 4.6K Nov 29 21:55 lrucache.lua
    -rwxr-xr-x 1 root root 1.2K Nov 29 21:55 md5.lua
    -rwxr-xr-x 1 root root  15K Nov 29 21:55 memcached.lua
    -rwxr-xr-x 1 root root 3.1K Nov 29 21:55 misc.lua
    -rwxr-xr-x 1 root root  20K Nov 29 21:55 mysql.lua
    -rwxr-xr-x 1 root root 8.5K Nov 29 21:55 protocol.lua
    -rwxr-xr-x 1 root root  17K Nov 29 21:55 pureffi.lua
    -rwxr-xr-x 1 root root  612 Nov 29 21:55 random.lua
    -rwxr-xr-x 1 root root  11K Nov 29 21:55 redis.lua
    -rwxr-xr-x 1 root root  23K Nov 29 21:55 regex.lua
    -rwxr-xr-x 1 root root 8.5K Nov 29 21:55 request.lua
    -rwxr-xr-x 1 root root  19K Nov 29 21:55 resolver.lua
    -rwxr-xr-x 1 root root 4.1K Nov 29 21:55 response.lua
    -rwxr-xr-x 1 root root 4.8K Nov 29 21:55 server.lua
    -rwxr-xr-x 1 root root  236 Nov 29 21:55 sha.lua
    -rwxr-xr-x 1 root root 1.2K Nov 29 21:55 sha1.lua
    -rwxr-xr-x 1 root root 1.1K Nov 29 21:55 sha224.lua
    -rwxr-xr-x 1 root root 1.3K Nov 29 21:55 sha256.lua
    -rwxr-xr-x 1 root root 1.1K Nov 29 21:55 sha384.lua
    -rwxr-xr-x 1 root root 1.4K Nov 29 21:55 sha512.lua
    -rwxr-xr-x 1 root root 9.1K Nov 29 21:55 shdict.lua
    -rwxrwxr-x 1 root root  12K Feb  9  2015 socket.lua
    -rwxr-xr-x 1 root root  694 Nov 29 21:55 string.lua
    -rwxr-xr-x 1 root root  436 Nov 29 21:55 time.lua
    -rwxr-xr-x 1 root root 5.1K Nov 29 21:55 upload.lua
    -rwxr-xr-x 1 root root 1.7K Nov 29 21:55 uri.lua
    -rwxr-xr-x 1 root root 3.0K Nov 29 21:55 var.lua
    -rwxr-xr-x 1 root root  445 Nov 29 21:55 worker.lua