lua-nginx-module

Nginx 中嵌入 Lua 语言
授权协议 BSD
开发语言 C/C++
所属分类 服务器软件、 Nginx扩展模块
软件类型 开源软件
地区 不详
投 递 者 充鑫鹏
操作系统 Windows
开源组织
适用人群 未知
 软件概览

lua-nginx-module (ngx_lua) 可在 Nginx 中嵌入 Lua 语言。让 Nginx 可以支持 Lua 强大的语法。

概要:

# set search paths for pure Lua external libraries (';;' is the default path):
 lua_package_path '/foo/bar/?.lua;/blah/?.lua;;';

 # set search paths for Lua external libraries written in C (can also use ';;'):
 lua_package_cpath '/bar/baz/?.so;/blah/blah/?.so;;';

 server {
     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 = /request_body {
         client_max_body_size 50k;
         client_body_buffer_size 50k;

         content_by_lua_block {
             ngx.req.read_body()  -- explicitly read the req body
             local data = ngx.req.get_body_data()
             if data then
                 ngx.say("body data:")
                 ngx.print(data)
                 return
             end

             -- body may get buffered in a temp file:
             local file = ngx.req.get_body_file()
             if file then
                 ngx.say("body is in file ", file)
             else
                 ngx.say("no body found")
             end
         }
     }

     # transparent non-blocking I/O in Lua via subrequests
     # (well, a better way is to use cosockets)
     location = /lua {
         # MIME type determined by default_type:
         default_type 'text/plain';

         content_by_lua_block {
             local res = ngx.location.capture("/some_other_location")
             if res then
                 ngx.say("status: ", res.status)
                 ngx.say("body:")
                 ngx.print(res.body)
             end
         }
     }

     location = /foo {
         rewrite_by_lua_block {
             res = ngx.location.capture("/memc",
                 { args = { cmd = "incr", key = ngx.var.uri } }
             )
         }

         proxy_pass http://blah.blah.com;
     }

     location = /mixed {
         rewrite_by_lua_file /path/to/rewrite.lua;
         access_by_lua_file /path/to/access.lua;
         content_by_lua_file /path/to/content.lua;
     }

     # use nginx var in code path
     # CAUTION: contents in nginx var must be carefully filtered,
     # otherwise there'll be great security risk!
     location ~ ^/app/([-_a-zA-Z0-9/]+) {
         set $path $1;
         content_by_lua_file /path/to/lua/app/root/$path.lua;
     }

     location / {
        client_max_body_size 100k;
        client_body_buffer_size 100k;

        access_by_lua_block {
            -- check the client IP address is in our black list
            if ngx.var.remote_addr == "132.5.72.3" then
                ngx.exit(ngx.HTTP_FORBIDDEN)
            end

            -- check if the URI contains bad words
            if ngx.var.uri and
                   string.match(ngx.var.request_body, "evil")
            then
                return ngx.redirect("/terms_of_use.html")
            end

            -- tests passed
        }

        # proxy_pass/fastcgi_pass/etc settings
     }
 }

 

  • Nginx安装lua-nginx-module模块 ngx_lua_module 是一个nginx http模块,它把 lua 解析器内嵌到 nginx,用来解析并执行lua 语言编写的网页后台脚本 特性很牛叉,可自行百度查看,这里主要是示范一下,如何在Nginx下安装lua-nginx-module模块 当然,如果你之前没有安装过Nginx,而且嫌安装麻烦,可直接下载openresty安装简单快

  • 需要LuaJIT-2.0.4.tar.gz,ngx_devel_kit,lua-nginx-module 1.下载安装LuaJIT-2.0.5.tar.gz http://luajit.org/download.html  wget -c http://luajit.org/download/LuaJIT-2.0.5.tar.gz tar xzvf LuaJIT-2.0.5.tar.gz cd L

  • 1.软件版本 系统版本:CentOS Linux release 7.3.1611 (Core) nginx版本:nginx-1.11.10 nginx-lua-moudle版本:lua-nginx-module 0.10.7 2.环境准备 安装编译所需的依赖 yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl opens

  • nginx安装lua-nginx-module模块,需要单独安装LuaJIT2.x编译器 下载地址:https://luajit.org/download.html 安装好之后设置环境变量 sudo vim /etc/profile 在文件中追加如下路径 export LUAJIT_LIB=/path/to/luajit/lib export LUAJIT_INC=/path/to/luajit

 相关资料
  • 本文向大家介绍Lua教程(一):在C++中嵌入Lua脚本,包括了Lua教程(一):在C++中嵌入Lua脚本的使用技巧和注意事项,需要的朋友参考一下 本系列教程主要介绍如何在C/C++程序里面嵌入Lua脚本,我打算从以下几个方面来介绍: 1.如何在C/C++里面嵌入Lua脚本 2.Lua访问C/C++数据结构(这里面要介绍类,结构体,函数,变量,枚举等数据类型在lua里面如何访问) 3.C/C++访

  • This module embeds the Lua interpreter or LuaJIT into the nginx core and integrates the powerful Lua threads (aka Lua coroutines) into the nginx event model by means of nginx subrequests. Unlike Apach

  • Nginx与Lua编写脚本的基本构建块是指令执行顺序的图 Nginx 教程 基础 Nginx编译安装 Nginx.conf详解 Location 详解 Nginx基础知识 Nginx高性能WEB服务器详解 Nginx高并发系统内核优化和PHP7配置文件优化 Nginx和PHP-FPM启动脚本 Nginx的11个Phases agentzh 的 Nginx 教程 Nginx 陷阱和常见错误 TCP和

  • This Nginx C module exposes a Lua API to Lua Nginx Module for classic Nginx upstreams. Documentation: https://github.com/agentzh/lua-upstream-nginx-module Project page: https://github.com/agentzh/lua-

  • ngx_tcp_lua_module-将Lua的功能嵌入Nginx服务器。在tcp流模式下工作。 基于nginx1.4.1版本, 本着精简,高效,模块化等原则,吸收nginx-http-lua模块(https://github.com/openresty/lua-nginx-module), tcp_lua模块(https://github.com/bigplum/nginx-tcp-lua-mo

  • nginx-lua-ds-loadbalancer 是一个HTTP负载均衡器,基于liseen/lua-resty-http A http loadbalancer which is based on liseen/lua-resty-http 将代码放在位于nginx根目录下的lua/ds_lb/下 Put the code into the directory lua/ds_lb which