1、Nginx 简介

Nginx 作为一款面向性能设计的HTTP服务器,相较于Apache、lighttpd具有占有内存少,稳定性高等优势。其流行度越来越高,应用也越来越广泛,常见的应用有:网页服务器、反向代理服务器以及电子邮件(IMAP/POP3)代理服务器,高并发大流量站点常用来做接入层的负载均衡,还有非常常见的用法是作为日志采集服务器等。

Nginx 整体采用模块化设计,有丰富的模块库和第三方模块库,配置灵活。其中模块化设计是nginx的一大卖点,甚至http服务器核心功能也是一个模块。要注意的是:nginx的模块是静态的,添加和删除模块都要对nginx进行重新编译,这一点与Apache的动态模块完全不同。不过后来淘宝做了二次开发开源的 tengine 是支持 官方所有的 HTTP 模块动态加载而不必重新编译 Nginx,除非是第三方模块才需要重新编译。因此,在生产环境中,推荐用淘宝开源的 tengine,本文也以 tengine 作为示例。

虽然 Nginx 有如此强大的性能以及众多的三方模块支持,但每次重新编译以及寻找三方模块对生产环境来说还是不可接受的,幸运的是,Nginx 它是支持客户自己 Lua 脚本编程扩展相应的功能的,而且可以热加载,这就给生产环境带来了无限可能。比如我现在想要直接用Nginx + redis 做反爬虫和频率限制,Nginx + Kafka 做日志的实时流处理等等。

注:lvs 和 nginx 的负载均衡区别:

LVS:Linux Virtual Server,基于IP的负载均衡和反向代理技术,所以它几乎可以对所有应用做负载均衡,包括http、数据库、在线聊天室等等,LVS工作在4层,在Linux内核中作四层交换,只花128个字节记录一个连接信息,不涉及到文件句柄操作,故没有65535最大文件句柄数的限制。LVS性能很高,可以支持100~400万条并发连接。抗负载能力强、是工作在网络4层之上仅作分发之用,没有流量的产生,这个特点也决定了它在负载均衡软件里的性能最强的,对内存和cpu、IO资源消耗比较低。 

Nginx:基于HTTP的负载均衡和反向代理服务器,Nginx工作在网络的7层,所以它可以针对http应用本身来做分流策略,比如针对域名、URL、目录结构等,相比之下LVS并不具备这样的功能,能够很好地支持虚拟主机,可配置性很强,大约能支持3~5万条并发连接。

2、Lua 简介

Lua 是一个简洁、轻量、可扩展的脚本语言,也是号称性能最高的脚本语言,用在很多需要性能的地方,比如:游戏脚本,nginx,wireshark的脚本,当你把他的源码下下来编译后,你会发现解释器居然不到200k,非常变态。。。很多应用程序使用Lua作为自己的嵌入式脚本语言,以此来实现可配置性、可扩展性。

 

Lua原生支持的数据类型非常之少,它只提供了nil、数字(缺省是双精度浮点数,可配置)、布尔量、字符串、表、子程序、协程(coroutine)以及用户自定义数据这8种。但是其处理表和字符串的效率非常之高,加上元表的支持,开发者可以高效的模拟出需要的复杂数据类型(比如集合、数组等)。Lua是一个动态弱类型语言,支持增量式垃圾收集策略。有内建的,与操作系统无关的协作式多线程(coroutine)支持。它还可以用于嵌入式硬件,不仅可以嵌入其他编程语言,而且可以嵌入微处理器中。

3、nginx执行步骤

nginx在处理每一个用户请求时,都是按照若干个不同的阶段依次处理的,与配置文件上的顺序没有关系,详细内容可以阅读《深入理解nginx:模块开发与架构解析》这本书,这里只做简单介绍;

(1)post-read

读取请求内容阶段,nginx读取并解析完请求头之后就立即开始运行;

(2)server-rewrite

server请求地址重写阶段;

(3)find-config

配置查找阶段,用来完成当前请求与location配重块之间的配对工作;

(4)rewrite

location请求地址重写阶段,当ngx_rewrite指令用于location中,就是再这个阶段运行的;

(5)post-rewrite

请求地址重写提交阶段,当nginx完成rewrite阶段所要求的内部跳转动作,如果rewrite阶段有这个要求的话;

(6)preaccess

访问权限检查准备阶段,ngx_limit_req和ngx_limit_zone在这个阶段运行,ngx_limit_req可以控制请求的访问频率,ngx_limit_zone可以控制访问的并发度;

(7)access

权限检查阶段,ngx_access在这个阶段运行,配置指令多是执行访问控制相关的任务,如检查用户的访问权限,检查用户的来源IP是否合法;

(8)post-access

访问权限检查提交阶段;

(9)try-files

配置项try_files处理阶段;

(10)content

内容产生阶段,是所有请求处理阶段中最为重要的阶段,因为这个阶段的指令通常是用来生成HTTP响应内容的;

(11)log

日志模块处理阶段;

图:Nginx 模块执行顺序与阶段

4、ngx_lua 运行指令

ngx_lua属于nginx的一部分,它的执行指令都包含在nginx的11个步骤之中了,相应的处理阶段可以做插入式处理,即可插拔式架构,不过ngx_lua并不是所有阶段都会运行的;另外指令可以在http、server、server if、location、location if几个范围进行配置:

指令

所处处理阶段

使用范围

解释

init_by_lua

init_by_lua_file

loading-config

http

nginx Master进程加载配置时执行;

通常用于初始化全局配置/预加载Lua模块

init_worker_by_lua

init_worker_by_lua_file

starting-worker

http

每个Nginx Worker进程启动时调用的计时器,如果Master进程不允许则只会在init_by_lua之后调用;

通常用于定时拉取配置/数据,或者后端服务的健康检查

set_by_lua

set_by_lua_file

rewrite

server,server if,location,location if

设置nginx变量,可以实现复杂的赋值逻辑;此处是阻塞的,Lua代码要做到非常快;

rewrite_by_lua

rewrite_by_lua_file

rewrite tail

http,server,location,location if

rrewrite阶段处理,可以实现复杂的转发/重定向逻辑;

access_by_lua

access_by_lua_file

access tail

http,server,location,location if

请求访问阶段处理,用于访问控制

content_by_lua

content_by_lua_file

content

location,location if

内容处理器,接收请求处理并输出响应

header_filter_by_lua

header_filter_by_lua_file

output-header-filter

http,server,location,location if

设置header和cookie

body_filter_by_lua

body_filter_by_lua_file

output-body-filter

http,server,location,location if

对响应数据进行过滤,比如截断、替换。

log_by_lua

log_by_lua_file

log

http,server,location,location if

log阶段处理,比如记录访问量/统计平均响应时间

关于这部分详细可以参考这篇:

Refer [4] nginx与lua的执行顺序和步骤说明  

Refer [5] ngx_lua用例说明

5、安装 tengine 以及 Lua 扩展

 

(1)先安装Nginx需要的一些类库:

yum install gcc

yum install gcc-c++

注:此步骤只是在你的系统没有安装 gcc/gcc-c++ 的情况下才需要自行编译安装。

(2)编译安装库LuaJit-2.0.3:

./configure --prefix=/usr/local/luajit

make PREFIX=/usr/local/luajit

make install PREFIX=/usr/local/luajit

在/etc/profile文件中增加环境变量,并执行 source /etc/profile 使之生效(非必须):

export LUAJIT_LIB=/usr/install/luajit/lib

export LUAJIT_INC=/usr/install/luajit/include/luajit-2.0

注:此步骤只是在你的系统没有安装 LuaJIT 的情况下才需要自行编译安装。

(3)下载模块依赖 pcre-8.34、zlib-1.2.8、ngx_devel_kit 和 lua-nginx-module,最后编译Nginx:

完整的参数可能这样:


nginx&nbsp;-V<br />

Tengine&nbsp;version:&nbsp;Tengine/<span class="hljs-number"><span class="hljs-number">2.1</span></span><span class="hljs-number"><span class="hljs-number">.0</span></span>&nbsp;(nginx/<span class="hljs-number"><span class="hljs-number">1.6</span></span><span class="hljs-number"><span class="hljs-number">.2</span></span>)<br />
built&nbsp;by&nbsp;gcc&nbsp;<span class="hljs-number"><span class="hljs-number">4.4</span></span><span class="hljs-number"><span class="hljs-number">.7</span></span>&nbsp;<span class="hljs-number"><span class="hljs-number">20120313</span></span>&nbsp;(Red&nbsp;Hat&nbsp;<span class="hljs-number"><span class="hljs-number">4.4</span></span><span class="hljs-number"><span class="hljs-number">.7</span></span><span class="hljs-number"><span class="hljs-number">-4</span></span>)&nbsp;(GCC)&nbsp;<br />
TLS&nbsp;SNI&nbsp;support&nbsp;enabled<br />
configure&nbsp;<span class="hljs-built_in"><span class="hljs-built_in">arguments</span></span>:&nbsp;--prefix=<span class="hljs-regexp"><span class="hljs-regexp">/etc/</span></span>nginx/&nbsp;--sbin-path=<span class="hljs-regexp"><span class="hljs-regexp">/usr/</span></span>sbin/nginx&nbsp;--conf-path=<span class="hljs-regexp"><span class="hljs-regexp">/etc/</span></span>nginx/nginx.conf&nbsp;--error-log-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/</span></span>log/nginx/error.log&nbsp;--http-log-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/</span></span>log/nginx/access.log&nbsp;--pid-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/</span></span>run/nginx.pid&nbsp;--lock-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/</span></span>run/nginx.lock&nbsp;--http-client-body-temp-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/</span></span>cache/nginx/client_temp&nbsp;--http-proxy-temp-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/</span></span>cache/nginx/proxy_temp&nbsp;--http-fastcgi-temp-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/</span></span>cache/nginx/fastcgi_temp&nbsp;--http-uwsgi-temp-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/</span></span>cache/nginx/uwsgi_temp&nbsp;--http-scgi-temp-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/</span></span>cache/nginx/scgi_temp&nbsp;--user=nginx&nbsp;--group=nginx&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">with</span></span>-http_ssl_module&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">with</span></span>-http_realip_module&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">with</span></span>-http_addition_module&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">with</span></span>-http_sub_module&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">with</span></span>-http_dav_module&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">with</span></span>-http_flv_module&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">with</span></span>-http_mp4_module&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">with</span></span>-http_gzip_static_module&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">with</span></span>-http_random_index_module&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">with</span></span>-http_secure_link_module&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">with</span></span>-http_stub_status_module&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">with</span></span>-mail&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">with</span></span>-mail_ssl_module&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">with</span></span>-file-aio&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">with</span></span>-ipv6&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">with</span></span>-cc-opt=<span class="hljs-string"><span class="hljs-string">'-O2&nbsp;-g&nbsp;-m64&nbsp;-mtune=generic'</span></span>&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">with</span></span>-pcre=../pcre<span class="hljs-number"><span class="hljs-number">-8.33</span></span>&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">with</span></span>-zlib=../zlib<span class="hljs-number"><span class="hljs-number">-1.2</span></span><span class="hljs-number"><span class="hljs-number">.8</span></span>&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">with</span></span>-openssl=../openssl<span class="hljs-number"><span class="hljs-number">-1.0</span></span><span class="hljs-number"><span class="hljs-number">.1</span></span>l

先 ./configure 各种配置参数以及模块路径,但我这里只是用来测试就精简了不少参数:


./configure&nbsp;--prefix=<span class="hljs-regexp"><span class="hljs-regexp">/opt/soft</span></span><span class="hljs-regexp"><span class="hljs-regexp">/nginx&nbsp;--with-pcre=/root</span></span><span class="hljs-regexp"><span class="hljs-regexp">/soft/pcre</span></span>-<span class="hljs-number"><span class="hljs-number">8.37</span></span>&nbsp;--with-zlib=<span class="hljs-regexp"><span class="hljs-regexp">/root/soft</span></span><span class="hljs-regexp"><span class="hljs-regexp">/zlib-1.2.8&nbsp;--with-openssl=/root</span></span><span class="hljs-regexp"><span class="hljs-regexp">/soft/openssl</span></span>-<span class="hljs-number"><span class="hljs-number">1.0</span></span>.<span class="hljs-number"><span class="hljs-number">1</span></span>p&nbsp;&nbsp;--add-<span class="hljs-keyword"><span class="hljs-keyword">module</span></span>=<span class="hljs-regexp"><span class="hljs-regexp">/root/soft</span></span><span class="hljs-regexp"><span class="hljs-regexp">/lua-nginx-module-master&nbsp;--add-module=/root</span></span><span class="hljs-regexp"><span class="hljs-regexp">/soft/ngx</span></span>_devel_kit-master&nbsp;--sbin-path=<span class="hljs-regexp"><span class="hljs-regexp">/usr/sbin</span></span><span class="hljs-regexp"><span class="hljs-regexp">/nginx&nbsp;--conf-path=/etc</span></span><span class="hljs-regexp"><span class="hljs-regexp">/nginx/nginx</span></span>.conf&nbsp;--error-log-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/log</span></span><span class="hljs-regexp"><span class="hljs-regexp">/nginx/error</span></span>.log&nbsp;--http-log-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/log</span></span><span class="hljs-regexp"><span class="hljs-regexp">/nginx/access</span></span>.log&nbsp;--pid-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/run</span></span><span class="hljs-regexp"><span class="hljs-regexp">/nginx.pid&nbsp;--lock-path=/var</span></span><span class="hljs-regexp"><span class="hljs-regexp">/run/nginx</span></span>.lock&nbsp;--http-client-body-temp-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/cache</span></span><span class="hljs-regexp"><span class="hljs-regexp">/nginx/client</span></span>_temp&nbsp;--http-proxy-temp-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/cache</span></span><span class="hljs-regexp"><span class="hljs-regexp">/nginx/proxy</span></span>_temp&nbsp;--http-fastcgi-temp-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/cache</span></span><span class="hljs-regexp"><span class="hljs-regexp">/nginx/fastcgi</span></span>_temp&nbsp;--http-uwsgi-temp-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/cache</span></span><span class="hljs-regexp"><span class="hljs-regexp">/nginx/uwsgi</span></span>_temp&nbsp;--http-scgi-temp-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/cache</span></span><span class="hljs-regexp"><span class="hljs-regexp">/nginx/scgi</span></span>_temp

然后 make、make install 即可。

(5)启动Nginx sbin/nginx,浏览器输入http://localhost测试

需要注意的是:

(1)--with-pcre=/root/soft/pcre-8.37 --with-zlib=/root/soft/zlib-1.2.8 指向的是源码路径,而非编译后的路径,否则 make 会报:


<span class="hljs-built_in"><span class="hljs-built_in">cd</span></span>&nbsp;/usr/<span class="hljs-built_in"><span class="hljs-built_in">local</span></span>/pcre&nbsp;\<br />

&amp;&amp;&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">if</span></span>&nbsp;[&nbsp;<span class="hljs-_"><span class="hljs-_">-f</span></span>&nbsp;Makefile&nbsp;];&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">then</span></span>&nbsp;make&nbsp;distclean;&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">fi</span></span>&nbsp;\<br />
&amp;&amp;&nbsp;CC=<span class="hljs-string"><span class="hljs-string">"gcc"</span></span>&nbsp;CFLAGS=<span class="hljs-string"><span class="hljs-string">"-O2&nbsp;-fomit-frame-pointer&nbsp;-pipe&nbsp;"</span></span>&nbsp;\<br />
./configure&nbsp;--disable-shared<br />
/bin/sh:&nbsp;./configure:&nbsp;No&nbsp;such&nbsp;file&nbsp;or&nbsp;directory<br />
make[1]:&nbsp;***&nbsp;[/usr/<span class="hljs-built_in"><span class="hljs-built_in">local</span></span>/pcre/Makefile]&nbsp;Error&nbsp;127<br />
make[1]:&nbsp;Leaving&nbsp;directory&nbsp;`/software/nginx-0.8.53<span class="hljs-string"><span class="hljs-string">'<br />
make:&nbsp;***&nbsp;[build]&nbsp;Error&nbsp;2</span></span>

 

因为 ./configure --help 看一下帮助说明:

--with-pcre=DIR                 set path to PCRE library sources

set path to PCRE library sources 是让你设置到源码目录,而不是编译安装后的目录

(2)pcre、zlib、openssl 等系统库如果系统没有集成自带,一定要单独编译安装,而 lua-nginx-module、ngx_devel_kit 等插件模块只需要指源码路径给 nginx 一起编译即可,不需要单独编译。

6、一个 Nginx + Lua 测试的例子


user work work;<br />

worker_processes  <span class="hljs-number"><span class="hljs-number">7</span></span>;<br />
<br />
error_log  /opt/data1/logs/nginx/error.log;<br />
pid        /<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>/run/nginx.pid;<br />
worker_rlimit_nofile <span class="hljs-number"><span class="hljs-number">800000</span></span>;<br />
<br />
events {<br />
    use epoll;<br />
    worker_connections  <span class="hljs-number"><span class="hljs-number">65535</span></span>;<br />
}<br />
<br />
http {<br />
    <br />
    server {<br />
        listen    <span class="hljs-number"><span class="hljs-number">80</span></span>;<br />
<br />
        <span class="hljs-keyword"><span class="hljs-keyword">set</span></span> $idTest <span class="hljs-string"><span class="hljs-string">"idTest_11111111111"</span></span> ;<br />
        log_format  tracklog '$idTest $msec $remote_addr - $remote_user [$time_local] $request '<br />
                        '<span class="hljs-string"><span class="hljs-string">"$status"</span></span> resp_body:<span class="hljs-string"><span class="hljs-string">"$resp_body"</span></span> --<span class="hljs-string"><span class="hljs-string">"$ref1"</span></span>-- '<br />
                        '<span class="hljs-string"><span class="hljs-string">"$http_user_agent"</span></span>';<br />
                        <br />
        location ~ /gzip/(.*) {<br />
            default_type <span class="hljs-string"><span class="hljs-string">"text/html"</span></span>;<br />
        <br />
            <span class="hljs-keyword"><span class="hljs-keyword">set</span></span> $resp_body <span class="hljs-string"><span class="hljs-string">""</span></span>;<br />
            content_by_lua  '   <br />
            --zlib 解码 post gzip 数据<br />
            local zlib = require <span class="hljs-string"><span class="hljs-string">"zlib"</span></span><br />
            local encoding = ngx.req.get_headers()[<span class="hljs-string"><span class="hljs-string">"Content-Encoding"</span></span>]<br />
            <br />
            <span class="hljs-keyword"><span class="hljs-keyword">if</span></span> encoding == <span class="hljs-string"><span class="hljs-string">"gzip"</span></span> then<br />
                ngx.req.read_body()<br />
                local body = ngx.req.get_body_data()<br />
                ngx.say(<span class="hljs-string"><span class="hljs-string">"++++++++++++++++++++++++++++body data:"</span></span>)<br />
                ngx.<span class="hljs-built_in"><span class="hljs-built_in">print</span></span>(body)<br />
                <span class="hljs-keyword"><span class="hljs-keyword">if</span></span> body then<br />
                    --ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.resp_body = <span class="hljs-string"><span class="hljs-string">"55555555555555"</span></span><br />
                    local stream = zlib.inflate()<br />
                    ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.resp_body = stream(body)<br />
                end<br />
            end<br />
        ';<br />
            <br />
            access_log  on;<br />
            access_log              /opt/data1/logs/nginx/pc/track/ooxx.com.access.log               tracklog;<br />
        }<br />
<br />
        location ~ /post/(.*) {<br />
            default_type <span class="hljs-string"><span class="hljs-string">"text/html"</span></span>;<br />
            lua_need_request_body on;                                                                                            <br />
            <span class="hljs-keyword"><span class="hljs-keyword">set</span></span> $resp_body <span class="hljs-string"><span class="hljs-string">""</span></span>;<br />
            content_by_lua  '   <br />
            ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.resp_body = ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.request_body<br />
        ';<br />
            <br />
            access_log  on;<br />
            access_log              /opt/data1/logs/nginx/pc/track/ooxx.com.access.log               tracklog;<br />
        }<br />
        <br />
    <br />
        location ~ /lua/(.*) {<br />
            default_type <span class="hljs-string"><span class="hljs-string">"text/html"</span></span>;  <br />
            <span class="hljs-keyword"><span class="hljs-keyword">set</span></span> $ref1 <span class="hljs-string"><span class="hljs-string">"Hello,Nginx &amp; Lua !"</span></span>;    <br />
            #设置nginx变量  <br />
            <span class="hljs-keyword"><span class="hljs-keyword">set</span></span> $a $<span class="hljs-number"><span class="hljs-number">1</span></span>;   <br />
            <span class="hljs-keyword"><span class="hljs-keyword">set</span></span> $b $host;<br />
        <br />
        content_by_lua '   <br />
            --nginx变量  <br />
            local <span class="hljs-keyword"><span class="hljs-keyword">var</span></span> = ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>  <br />
            ngx.say(<span class="hljs-string"><span class="hljs-string">"ngx.var.a : "</span></span>, <span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.a, <span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)  <br />
            ngx.say(<span class="hljs-string"><span class="hljs-string">"ngx.var.b : "</span></span>, <span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.b, <span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)  <br />
            ngx.say(<span class="hljs-string"><span class="hljs-string">"ngx.var[2] : "</span></span>, <span class="hljs-keyword"><span class="hljs-keyword">var</span></span>[<span class="hljs-number"><span class="hljs-number">2</span></span>], <span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)  <br />
            ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.b = <span class="hljs-number"><span class="hljs-number">2</span></span>;  <br />
            ngx.say(<span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)  <br />
  <br />
            --请求头  <br />
           ngx.say(ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.httpRef, <span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)<br />
           local headers = ngx.req.get_headers()  <br />
           <span class="hljs-keyword"><span class="hljs-keyword">for</span></span> k,v <span class="hljs-keyword"><span class="hljs-keyword">in</span></span> pairs(headers) <span class="hljs-keyword"><span class="hljs-keyword">do</span></span>  <br />
                <span class="hljs-keyword"><span class="hljs-keyword">if</span></span> type(v) == <span class="hljs-string"><span class="hljs-string">"table"</span></span> then  <br />
                    ngx.say(k, <span class="hljs-string"><span class="hljs-string">" : "</span></span>, table.concat(v, <span class="hljs-string"><span class="hljs-string">","</span></span>), <span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)  <br />
                <span class="hljs-keyword"><span class="hljs-keyword">else</span></span>  <br />
                    ngx.say(k, <span class="hljs-string"><span class="hljs-string">" : "</span></span>, v, <span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)  <br />
                end  <br />
            end  <br />
            ngx.say(<span class="hljs-string"><span class="hljs-string">"------------headers end-----------"</span></span>, <span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;"</span></span>)  <br />
            <br />
            --<span class="hljs-keyword"><span class="hljs-keyword">get</span></span>请求uri参数  <br />
            ngx.say(<span class="hljs-string"><span class="hljs-string">"uri args begin"</span></span>, <span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)  <br />
            local uri_args = ngx.req.get_uri_args()  <br />
            <span class="hljs-keyword"><span class="hljs-keyword">for</span></span> k, v <span class="hljs-keyword"><span class="hljs-keyword">in</span></span> pairs(uri_args) <span class="hljs-keyword"><span class="hljs-keyword">do</span></span>  <br />
                <span class="hljs-keyword"><span class="hljs-keyword">if</span></span> type(v) == <span class="hljs-string"><span class="hljs-string">"table"</span></span> then  <br />
                    ngx.say(k, <span class="hljs-string"><span class="hljs-string">" : "</span></span>, table.concat(v, <span class="hljs-string"><span class="hljs-string">", "</span></span>), <span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)  <br />
                <span class="hljs-keyword"><span class="hljs-keyword">else</span></span>  <br />
                    ngx.say(k, <span class="hljs-string"><span class="hljs-string">": "</span></span>, v, <span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)  <br />
                end  <br />
            end  <br />
            ngx.say(<span class="hljs-string"><span class="hljs-string">"uri args end"</span></span>, <span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)  <br />
            ngx.say(<span class="hljs-string"><span class="hljs-string">"a: "</span></span>,ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.arg_a, <span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)<br />
            ngx.say(<span class="hljs-string"><span class="hljs-string">"b: "</span></span>,ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.arg_b, <span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)<br />
<br />
            --未经解码的请求 uri  <br />
            local request_uri = headers[<span class="hljs-string"><span class="hljs-string">"Host"</span></span>] .. <span class="hljs-string"><span class="hljs-string">"/"</span></span> .. ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.request_uri;  <br />
            ngx.say(<span class="hljs-string"><span class="hljs-string">"request_uri : "</span></span>, request_uri, <span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>);  <br />
            --解码后的 uri  <br />
            local decode_request_uri = headers[<span class="hljs-string"><span class="hljs-string">"Host"</span></span>] .. <span class="hljs-string"><span class="hljs-string">"/"</span></span> .. ngx.unescape_uri(ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.request_uri); <br />
            ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.ref1 = decode_request_uri;<br />
            ngx.say(<span class="hljs-string"><span class="hljs-string">"decode request_uri : "</span></span>, decode_request_uri, <span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>);  <br />
            --<span class="hljs-type"><span class="hljs-type">MD5</span></span>  <br />
            ngx.say(<span class="hljs-string"><span class="hljs-string">"ngx.md5 : "</span></span>, ngx.md5(<span class="hljs-string"><span class="hljs-string">"123"</span></span>), <span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)  <br />
            --http time  <br />
            ngx.say(<span class="hljs-string"><span class="hljs-string">"ngx.http_time : "</span></span>, ngx.http_time(ngx.time()), <span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)  <br />
            --ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.http_referer = <span class="hljs-string"><span class="hljs-string">"*********************"</span></span><br />
            <br />
            ';<br />
            <br />
            <br />
    <br />
            log_format  <span class="hljs-type"><span class="hljs-type">LogFormatv1</span></span> '$idTest@$msec@$remote_addr@-@$remote_user@[$time_local]@$request@'<br />
                        '<span class="hljs-string"><span class="hljs-string">"$status"</span></span>@$body_bytes_sent@<span class="hljs-string"><span class="hljs-string">"$http_referer"</span></span>@'<br />
                        '<span class="hljs-string"><span class="hljs-string">"$http_user_agent"</span></span>';<br />
    <br />
            access_log  on;<br />
<br />
            access_log              /opt/data1/logs/nginx/<span class="hljs-type"><span class="hljs-type">PCv1</span></span>/track/ooxx.com.access.log               <span class="hljs-type"><span class="hljs-type">LogFormatv1</span></span>;<br />
        }<br />
<br />
    }<br />
}

需要注意的是线上的 Nginx 可能面对的是高并发场景,对于自己的 Lua 代码最好做个压力测试,比如:


tcpcopy&nbsp;<br />

<br />
或者<br />
<br />
ab&nbsp;-c100&nbsp;-n10000&nbsp;<span class="hljs-symbol"><span class="hljs-symbol">'http</span></span>:<span class="hljs-comment"><span class="hljs-comment">//test.abc.com/lua/test%20haha/?a=3&amp;b=4'</span></span>

7、关于 64bit Cgywin 下编译安装 Tengine 的一些问题

(1)openSSL 库不支持 64bit Cygwin


cryptlib.<span class="hljs-string"><span class="hljs-string">c:</span></span><span class="hljs-number"><span class="hljs-number">1</span></span>:<span class="hljs-number"><span class="hljs-number">0</span></span>:&nbsp;错误:您选择的&nbsp;CPU&nbsp;不支持&nbsp;x86<span class="hljs-number"><span class="hljs-number">-64</span></span>&nbsp;指令集<br />

&nbsp;<span class="hljs-comment"><span class="hljs-comment">/*&nbsp;crypto/cryptlib.c&nbsp;*/</span></span><br />
&nbsp;^<br />
cryptlib.<span class="hljs-string"><span class="hljs-string">c:</span></span><span class="hljs-number"><span class="hljs-number">1</span></span>:<span class="hljs-number"><span class="hljs-number">0</span></span>:&nbsp;错误:您选择的&nbsp;CPU&nbsp;不支持&nbsp;x86<span class="hljs-number"><span class="hljs-number">-64</span></span>&nbsp;指令集<br />
&lt;builtin&gt;:&nbsp;recipe&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">for</span></span>&nbsp;target&nbsp;<span class="hljs-string"><span class="hljs-string">'cryptlib.o'</span></span>&nbsp;failed<br />
make[<span class="hljs-number"><span class="hljs-number">3</span></span>]:&nbsp;***&nbsp;[cryptlib.o]&nbsp;Error&nbsp;<span class="hljs-number"><span class="hljs-number">1</span></span><br />
make[<span class="hljs-number"><span class="hljs-number">3</span></span>]:&nbsp;Leaving&nbsp;directory&nbsp;<span class="hljs-string"><span class="hljs-string">'/home/Jun/softs/openssl-1.0.1r/crypto'</span></span><br />
<span class="hljs-string"><span class="hljs-string">Makefile:</span></span><span class="hljs-number"><span class="hljs-number">281</span></span>:&nbsp;recipe&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">for</span></span>&nbsp;target&nbsp;<span class="hljs-string"><span class="hljs-string">'build_crypto'</span></span>&nbsp;failed

这种要么自己去网上找补丁 patch,要么换成 Cygwin 32bit,还有一种解决方案就是自己在安装 Cygwin 包的时候把 openssl 也装上,也就是说选择安装包的时候尽量装全一点。省得后续自己装遇到各种问题。

这样如果你自己已经装了 openssl 那么可以在configure 的时候去掉openssl 相关的编译依赖选项:

./configure  --with-openssl=/root/soft/openssl-1.0.1p (去掉该项) 

(2)nginx 启动报错:

nginx: [emerg] the maximum number of files supported by select() is 64

毕竟 Cygwin 还是依赖 windows的,各种参数得针对 windows 优化,比如这个报错是说默认配置文件里的 worker_connections 不能超过 64 个,你改成 20 即可。


<span class="hljs-section"><span class="hljs-section">events</span></span>&nbsp;{<br />

&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-attribute"><span class="hljs-attribute">use</span></span>&nbsp;<span class="hljs-literal"><span class="hljs-literal">epoll</span></span>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-attribute"><span class="hljs-attribute">worker_connections</span></span>&nbsp;&nbsp;<span class="hljs-number"><span class="hljs-number">65535</span></span>;<br />
}

比如我这里的编译配置参数是(注意有些目录可能需要提前自己创建):


.<span class="hljs-regexp"><span class="hljs-regexp">/configure&nbsp;--prefix=/</span></span>opt<span class="hljs-regexp"><span class="hljs-regexp">/soft/</span></span>nginx&nbsp;--with-pcre=<span class="hljs-regexp"><span class="hljs-regexp">/home/</span></span>Jun<span class="hljs-regexp"><span class="hljs-regexp">/softs/</span></span>pcre<span class="hljs-number"><span class="hljs-number">-8.38</span></span>&nbsp;--with-zlib=<span class="hljs-regexp"><span class="hljs-regexp">/home/</span></span>Jun<span class="hljs-regexp"><span class="hljs-regexp">/softs/</span></span>zlib<span class="hljs-number"><span class="hljs-number">-1.2</span></span><span class="hljs-number"><span class="hljs-number">.8</span></span>&nbsp;&nbsp;&nbsp;&nbsp;--add-module=<span class="hljs-regexp"><span class="hljs-regexp">/home/</span></span>Jun<span class="hljs-regexp"><span class="hljs-regexp">/softs/</span></span>ngx_devel_kit-master&nbsp;--add-module=<span class="hljs-regexp"><span class="hljs-regexp">/home/</span></span>Jun<span class="hljs-regexp"><span class="hljs-regexp">/softs/</span></span>echo-nginx-module-master&nbsp;&nbsp;--add-module=<span class="hljs-regexp"><span class="hljs-regexp">/home/</span></span>Jun<span class="hljs-regexp"><span class="hljs-regexp">/softs/</span></span>form-input-nginx-module-master&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--add-module=<span class="hljs-regexp"><span class="hljs-regexp">/home/</span></span>Jun<span class="hljs-regexp"><span class="hljs-regexp">/softs/</span></span>set-misc-nginx-module-master&nbsp;&nbsp;--add-module=<span class="hljs-regexp"><span class="hljs-regexp">/home/</span></span>Jun<span class="hljs-regexp"><span class="hljs-regexp">/softs/</span></span>lua-nginx-module-master&nbsp;--sbin-path=<span class="hljs-regexp"><span class="hljs-regexp">/usr/</span></span>sbin<span class="hljs-regexp"><span class="hljs-regexp">/nginx&nbsp;--conf-path=/</span></span>etc<span class="hljs-regexp"><span class="hljs-regexp">/nginx/</span></span>nginx.conf&nbsp;--error-log-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/</span></span>log<span class="hljs-regexp"><span class="hljs-regexp">/nginx/</span></span>error.log&nbsp;--http-log-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/</span></span>log<span class="hljs-regexp"><span class="hljs-regexp">/nginx/</span></span>access.log&nbsp;--pid-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/</span></span>run<span class="hljs-regexp"><span class="hljs-regexp">/nginx.pid&nbsp;--lock-path=/</span></span>var<span class="hljs-regexp"><span class="hljs-regexp">/run/</span></span>nginx.lock&nbsp;--http-client-body-temp-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/</span></span>cache<span class="hljs-regexp"><span class="hljs-regexp">/nginx/</span></span>client_temp&nbsp;--http-proxy-temp-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/</span></span>cache<span class="hljs-regexp"><span class="hljs-regexp">/nginx/</span></span>proxy_temp&nbsp;--http-fastcgi-temp-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/</span></span>cache<span class="hljs-regexp"><span class="hljs-regexp">/nginx/</span></span>fastcgi_temp&nbsp;--http-uwsgi-temp-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/</span></span>cache<span class="hljs-regexp"><span class="hljs-regexp">/nginx/</span></span>uwsgi_temp&nbsp;--http-scgi-temp-path=<span class="hljs-regexp"><span class="hljs-regexp">/var/</span></span>cache<span class="hljs-regexp"><span class="hljs-regexp">/nginx/</span></span>scgi_temp

最后 nginx.conf 稍加修改如下(注意有些目录可能需要提前自己创建):


worker_processes&nbsp;&nbsp;<span class="hljs-number"><span class="hljs-number">2</span></span>;<br />

&nbsp;<br />
#error_log&nbsp;&nbsp;/<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>/log/nginx/error.log;<br />
pid&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>/run/nginx.pid;<br />
&nbsp;<br />
events&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;worker_connections&nbsp;&nbsp;<span class="hljs-number"><span class="hljs-number">20</span></span>;<br />
}<br />
&nbsp;<br />
http&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;server&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;listen&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-number"><span class="hljs-number">80</span></span>;<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">set</span></span>&nbsp;$idTest&nbsp;<span class="hljs-string"><span class="hljs-string">"idTest_11111111111"</span></span>&nbsp;;<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log_format&nbsp;&nbsp;tracklog&nbsp;'$idTest&nbsp;$msec&nbsp;$remote_addr&nbsp;-&nbsp;$remote_user&nbsp;[$time_local]&nbsp;$request&nbsp;'<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'<span class="hljs-string"><span class="hljs-string">"$status"</span></span>&nbsp;$body_bytes_sent&nbsp;--<span class="hljs-string"><span class="hljs-string">"$ref1"</span></span>--&nbsp;'<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'<span class="hljs-string"><span class="hljs-string">"$http_user_agent"</span></span>';<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log_format&nbsp;&nbsp;<span class="hljs-type"><span class="hljs-type">LogFormatv1</span></span>&nbsp;'$idTest@$msec@$remote_addr@-@$remote_user@[$time_local]@$request@'<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'<span class="hljs-string"><span class="hljs-string">"$status"</span></span>@$body_bytes_sent@<span class="hljs-string"><span class="hljs-string">"$http_referer"</span></span>@'<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'<span class="hljs-string"><span class="hljs-string">"$http_user_agent"</span></span>';<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;access_log&nbsp;&nbsp;on;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;location&nbsp;~&nbsp;/lua/(.*)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default_type&nbsp;<span class="hljs-string"><span class="hljs-string">"text/html"</span></span>;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">set</span></span>&nbsp;$ref1&nbsp;<span class="hljs-string"><span class="hljs-string">"Hello,Nginx&nbsp;&amp;&nbsp;Lua&nbsp;!"</span></span>;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#设置nginx变量&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">set</span></span>&nbsp;$a&nbsp;$<span class="hljs-number"><span class="hljs-number">1</span></span>;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">set</span></span>&nbsp;$b&nbsp;$host;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content_by_lua&nbsp;'&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--nginx变量&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>&nbsp;=&nbsp;ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(<span class="hljs-string"><span class="hljs-string">"ngx.var.a&nbsp;:&nbsp;"</span></span>,&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.a,&nbsp;<span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(<span class="hljs-string"><span class="hljs-string">"ngx.var.b&nbsp;:&nbsp;"</span></span>,&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.b,&nbsp;<span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(<span class="hljs-string"><span class="hljs-string">"ngx.var[2]&nbsp;:&nbsp;"</span></span>,&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>[<span class="hljs-number"><span class="hljs-number">2</span></span>],&nbsp;<span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.b&nbsp;=&nbsp;<span class="hljs-number"><span class="hljs-number">2</span></span>;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(<span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--请求头&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.httpRef,&nbsp;<span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local&nbsp;headers&nbsp;=&nbsp;ngx.req.get_headers()&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">for</span></span>&nbsp;k,v&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">in</span></span>&nbsp;pairs(headers)&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">do</span></span>&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">if</span></span>&nbsp;type(v)&nbsp;==&nbsp;<span class="hljs-string"><span class="hljs-string">"table"</span></span>&nbsp;then&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(k,&nbsp;<span class="hljs-string"><span class="hljs-string">"&nbsp;:&nbsp;"</span></span>,&nbsp;table.concat(v,&nbsp;<span class="hljs-string"><span class="hljs-string">","</span></span>),&nbsp;<span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">else</span></span>&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(k,&nbsp;<span class="hljs-string"><span class="hljs-string">"&nbsp;:&nbsp;"</span></span>,&nbsp;v,&nbsp;<span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(<span class="hljs-string"><span class="hljs-string">"------------headers&nbsp;end-----------"</span></span>,&nbsp;<span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;"</span></span>)&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--<span class="hljs-keyword"><span class="hljs-keyword">get</span></span>请求uri参数&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(<span class="hljs-string"><span class="hljs-string">"uri&nbsp;args&nbsp;begin"</span></span>,&nbsp;<span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local&nbsp;uri_args&nbsp;=&nbsp;ngx.req.get_uri_args()&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">for</span></span>&nbsp;k,&nbsp;v&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">in</span></span>&nbsp;pairs(uri_args)&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">do</span></span>&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">if</span></span>&nbsp;type(v)&nbsp;==&nbsp;<span class="hljs-string"><span class="hljs-string">"table"</span></span>&nbsp;then&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(k,&nbsp;<span class="hljs-string"><span class="hljs-string">"&nbsp;:&nbsp;"</span></span>,&nbsp;table.concat(v,&nbsp;<span class="hljs-string"><span class="hljs-string">",&nbsp;"</span></span>),&nbsp;<span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword"><span class="hljs-keyword">else</span></span>&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(k,&nbsp;<span class="hljs-string"><span class="hljs-string">":&nbsp;"</span></span>,&nbsp;v,&nbsp;<span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(<span class="hljs-string"><span class="hljs-string">"uri&nbsp;args&nbsp;end"</span></span>,&nbsp;<span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(<span class="hljs-string"><span class="hljs-string">"a:&nbsp;"</span></span>,ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.arg_a,&nbsp;<span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(<span class="hljs-string"><span class="hljs-string">"b:&nbsp;"</span></span>,ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.arg_b,&nbsp;<span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--未经解码的请求&nbsp;uri&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local&nbsp;request_uri&nbsp;=&nbsp;headers[<span class="hljs-string"><span class="hljs-string">"Host"</span></span>]&nbsp;..&nbsp;<span class="hljs-string"><span class="hljs-string">"/"</span></span>&nbsp;..&nbsp;ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.request_uri;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(<span class="hljs-string"><span class="hljs-string">"request_uri&nbsp;:&nbsp;"</span></span>,&nbsp;request_uri,&nbsp;<span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>);&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--解码后的&nbsp;uri&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local&nbsp;decode_request_uri&nbsp;=&nbsp;headers[<span class="hljs-string"><span class="hljs-string">"Host"</span></span>]&nbsp;..&nbsp;<span class="hljs-string"><span class="hljs-string">"/"</span></span>&nbsp;..&nbsp;ngx.unescape_uri(ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.request_uri);&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.ref1&nbsp;=&nbsp;decode_request_uri;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(<span class="hljs-string"><span class="hljs-string">"decode&nbsp;request_uri&nbsp;:&nbsp;"</span></span>,&nbsp;decode_request_uri,&nbsp;<span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>);&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--<span class="hljs-type"><span class="hljs-type">MD5</span></span>&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(<span class="hljs-string"><span class="hljs-string">"ngx.md5&nbsp;:&nbsp;"</span></span>,&nbsp;ngx.md5(<span class="hljs-string"><span class="hljs-string">"123"</span></span>),&nbsp;<span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--http&nbsp;time&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(<span class="hljs-string"><span class="hljs-string">"ngx.http_time&nbsp;:&nbsp;"</span></span>,&nbsp;ngx.http_time(ngx.time()),&nbsp;<span class="hljs-string"><span class="hljs-string">"&lt;br/&gt;"</span></span>)&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--ngx.<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>.http_referer&nbsp;=&nbsp;<span class="hljs-string"><span class="hljs-string">"*********************"</span></span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;access_log&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/<span class="hljs-keyword"><span class="hljs-keyword">var</span></span>/log/nginx/ooxx.com.access.log&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tracklog;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}

最后 nginx -s reload 效果如下,http://localhost/lua/?a=1&b=2  请求也正常,和 linux 下结果一致:

8、关于 nginx 正则说明

(1)location 匹配语法规则

Nginx location 的正则匹配语法与优先级容易让新同学迷惑。

 

~      #波浪线表示执行一个正则匹配,区分大小写

~*    #表示执行一个正则匹配,不区分大小写

=      #进行普通字符精确匹配,与location在配置文件中的顺序无关,= 精确匹配会第一个被处理

@     #"@" 定义一个命名的 location,使用在内部定向时,例如 error_page, try_files

^~     标识符后面跟一个字符串。表示普通字符匹配,如果该选项匹配,只匹配该选项,不匹配别的选项,Nginx将在这个字符串匹配后停止进行正则表达式的匹配(location指令中正则表达式的匹配的结果优先使用),如:location ^~ /images/,你希望对/images/这个目录进行一些特别的操作,如增加expires头,防盗链等,但是你又想把除了这个目录的图片外的所有图片只进行增加expires头的操作,这个操作可能会用到另外一个location,例如:location ~* \.(gif|jpg|jpeg)$,这样,如果有请求/images/1.jpg,nginx如何决定去进行哪个location中的操作呢?结果取决于标识符^~,如果你这样写:location /images/,这样nginx会将1.jpg匹配到location ~* \.(gif|jpg|jpeg)$这个location中,这并不是你需要的结果,而增加了^~这个标识符后,它在匹配了/images/这个字符串后就停止搜索其它带正则的location。

例如:


location&nbsp;&nbsp;=&nbsp;/&nbsp;{<br />

&nbsp;&nbsp;<span class="hljs-meta"><span class="hljs-meta">#&nbsp;只匹配</span><span class="hljs-meta-string"><span class="hljs-meta"><span class="hljs-meta-string">"/"</span></span></span><span class="hljs-meta">.</span></span><br />
&nbsp;&nbsp;[&nbsp;configuration&nbsp;A&nbsp;]&nbsp;<br />
}<br />
location&nbsp;&nbsp;/&nbsp;{<br />
&nbsp;&nbsp;<span class="hljs-meta"><span class="hljs-meta">#&nbsp;匹配任何请求,因为所有请求都是以</span><span class="hljs-meta-string"><span class="hljs-meta"><span class="hljs-meta-string">"/"</span></span></span><span class="hljs-meta">开始</span></span><br />
&nbsp;&nbsp;<span class="hljs-meta"><span class="hljs-meta">#&nbsp;但是更长字符匹配或者正则表达式匹配会优先匹配</span></span><br />
&nbsp;&nbsp;[&nbsp;configuration&nbsp;B&nbsp;]&nbsp;<br />
}<br />
location&nbsp;^~&nbsp;/images/&nbsp;{<br />
&nbsp;&nbsp;<span class="hljs-meta"><span class="hljs-meta">#&nbsp;匹配任何以&nbsp;/images/&nbsp;开始的请求,并停止匹配&nbsp;其它location</span></span><br />
&nbsp;&nbsp;[&nbsp;configuration&nbsp;C&nbsp;]&nbsp;<br />
}<br />
location&nbsp;~*&nbsp;\.(gif|jpg|jpeg)$&nbsp;{<br />
&nbsp;&nbsp;<span class="hljs-meta"><span class="hljs-meta">#&nbsp;匹配以&nbsp;gif,&nbsp;jpg,&nbsp;or&nbsp;jpeg结尾的请求.&nbsp;</span></span><br />
&nbsp;&nbsp;<span class="hljs-meta"><span class="hljs-meta">#&nbsp;但是所有&nbsp;/images/&nbsp;目录的请求将由&nbsp;[Configuration&nbsp;C]处理.&nbsp;&nbsp;&nbsp;</span></span><br />
&nbsp;&nbsp;[&nbsp;configuration&nbsp;D&nbsp;]&nbsp;<br />
}

 

请求URI例子:

  • / -> 符合configuration A

  • /documents/document.html -> 符合configuration B

  • /images/1.gif -> 符合configuration C

  • /documents/1.jpg ->符合 configuration D

=      表示精确的查找地址,如location = /它只会匹配uri为/的请求,如果请求为/index.html,将查找另外的location,而不会匹配这个,当然可以写两个location,location = /和location /,这样/index.html将匹配到后者,如果你的站点对/的请求量较大,可以使用这个方法来加快请求的响应速度。

@      表示为一个location进行命名,即自定义一个location,这个location不能被外界所访问,只能用于Nginx产生的子请求,主要为error_page和try_files。

(2)location 优先级官方文档

  1. =前缀的指令严格匹配这个查询。如果找到,停止搜索。

  2. 所有剩下的常规字符串,最长的匹配。如果这个匹配使用^〜前缀,搜索停止。

  3. 正则表达式,在配置文件中定义的顺序。

  4. 如果第3条规则产生匹配的话,结果被使用。否则,如同从第2条规则被使用。

(3)正则语法

~      为区分大小写的匹配。

~*     不区分大小写的匹配(匹配firefox的正则同时匹配FireFox)。

!~     不匹配的

!~*    不匹配的

.     匹配除换行符以外的任意字符

\w     匹配字母或数字或下划线或汉字

\s     匹配任意的空白符

\d     匹配数字

\b     匹配单词的开始或结束

^     匹配字符串的开始

$     匹配字符串的结束

\W     匹配任意不是字母,数字,下划线,汉字的字符

\S     匹配任意不是空白符的字符

\D     匹配任意非数字的字符

\B     匹配不是单词开头或结束的位置

捕获     (exp)     匹配exp,并捕获文本到自动命名的组里

(?<name>exp)     匹配exp,并捕获文本到名称为name的组里,也可以写成(?'name'exp)

(?:exp)     匹配exp,不捕获匹配的文本,也不给此分组分配组号

零宽断言     (?=exp)     匹配exp前面的位置

(?<=exp)     匹配exp后面的位置

(?!exp)     匹配后面跟的不是exp的位置

(?<!exp)     匹配前面不是exp的位置

注释     (?#comment)     这种类型的分组不对正则表达式的处理产生任何影响,用于提供注释让人阅读

Refer:

[1] agentzh 的 Nginx 教程(版本 2015.03.19)

http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html

[2] HttpLuaModule

http://wiki.nginx.org/HttpLuaModule

[3] nginx lua api翻译

http://blog.csdn.net/imlsz/article/details/42915473

[4] nginx与lua的执行顺序和步骤说明

http://www.mrhaoting.com/?p=157

[5] ngx_lua用例说明

http://www.mrhaoting.com/?p=165

[6] 第二章 Nginx+Lua开发入门

http://jinnianshilongnian.iteye.com/blog/2186448

[7] 在Nginx使用Lua扩展功能

http://yikebocai.com/2014/11/generate-seqid-in-nginx-by-lua/

[8] nginx location匹配规则

http://www.nginx.cn/115.html

http://blog.csdn.net/gzh0222/article/details/7845981

[9] 平台服务部署及Web框架

http://weibo.com/p/1001643875679132642345

[10] 我所熟悉的网站负载均衡技术

http://zyan.cc/post/307/

[11] Nginx、LVS及HAProxy负载均衡软件的优缺点详解

http://www.csdn.net/article/2014-07-24/2820837

[12] Nginx 与 Lua 实现一个简单的服务端推方案

http://blogread.cn/it/article/5883?f=wb

[13] 深入 Nginx:我们是如何为性能和规模做设计的

http://blog.jobbole.com/88766/

[14] 本博客 Nginx 配置之性能篇

https://imququ.com/post/my-nginx-conf-for-wpo.html

[15] 系统负载能力浅析

http://www.rowkey.me/blog/2015/09/09/load-analysis/

[16] Nginx学习总结:常用module(二)

http://shift-alt-ctrl.iteye.com/blog/2231359

[16] 为最佳性能调优 Nginx

http://blog.jobbole.com/87531/

[17] Nginx 重写规则指南

http://www.techug.com/85916-2

[18] 跟我学Nginx+Lua开发目录贴

http://jinnianshilongnian.iteye.com/blog/2190344

[19] 第二章 Nginx+Lua开发入门

http://jinnianshilongnian.iteye.com/blog/2186448

[20] Nginx Third party modules

http://wiki.nginx.org/3rdPartyModules

[21] Tengine 新特性介绍

http://tengine.taobao.org/index_cn.html

[22] Nginx开发从入门到精通

http://tengine.taobao.org/book/

[23] Tengine dso动态加载模块

http://www.mylinuxer.com/532.html

[24] Tengine动态模块加载的使用方法

http://www.bkjia.com/Linux/992215.html#top

[25] OpenResty的现状、趋势、使用及学习方法

http://dwz.cn/2j0Dv1

[26] 使用nginx+lua+graphicmagick搭建图片处理服务器

http://shanks.leanote.com/post/Untitled-55ca439338f41148cd000759-23

[27] How to handle gziped capture?

https://github.com/openresty/lua-nginx-module/issues/12

[28] Nginx与Gzip请求

http://huoding.com/2013/09/02/283

 

 

via。https://my.oschina.net/leejun2005/blog/494248