安装Nginx1.6.2
升级Nginx1.8.1
Nginx下载模块
lua官网下载地址
LuaJIT下载页面


lua安装
1 2 3 4 5 6 7
| 1wget http://www.lua.org/ftp/lua-5.3.5.tar.gz
2tar -xf lua-5.3.5.tar.gz
3cd lua-5.3.4/
4make linux test
5make install
6
7 |


1 2 3 4 5 6 7
| 1wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz
2tar -xf LuaJIT-2.0.5.tar.gz
3cd LuaJIT-2.0.5/
4make
5make install PREFIX=/usr/local/LuaJIT
6
7 |

NDK(nginx development kit)模块是一个拓展nginx服务器核心功能的模块,第三方模块开发可以基于它来快速实现。 NDK提供函数和宏处理一些基本任务,减轻第三方模块开发的代码量。
下载ngx_devel_kit模块
下载lua-nginx-module模块
1 2 3 4 5 6 7
| 1wget https://github.com/simplresty/ngx_devel_kit/archive/v0.3.1.tar.gz
2wget https://github.com/openresty/lua-nginx-module/archive/v0.10.15.tar.gz
3cd /usr/local/nginx/module
4tar -xf v0.3.1.tar.gz
5tar -xf v0.10.15.tar.gz
6
7 |
添加设置luaJit的环境变量(如果这一步设置错误会报错:/configure: error: ngx_http_lua_module requires the Lua library.)

1 2 3 4
| 1export LUAJIT_INC=/usr/local/LuaJIT/include/luajit-2.0 #路径是上面luajit实际安装路径,路径错误安装lua模块时会报错很早不到luajit库
2export LUAJIT_LIB=/usr/local/LuaJIT/lib
3
4 |
预编译:
通过nginx -V获取之前预编译参数,并增加 –add-module参数
1 2 3 4 5
| 1yum -y install lua-devel
2cd /root/nginx-1.8.1
3./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-threads --user=www --group=www --add-module=/usr/local/nginx/module/echo-nginx-module-0.61 --add-module=/usr/local/nginx/module/lua-ssl-nginx-module-0.01rc3 --add-module=/usr/local/nginx/module/xss-nginx-module-0.06 --add-module=/usr/local/nginx/module/nginx-eval-module-2016.06.10 --add-module=/usr/local/nginx/module/ngx_devel_kit-0.3.1 --add-module=/usr/local/nginx/module/lua-nginx-module-0.10.15
4
5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| 1# 编译器
2./configure
3> --prefix=/usr/local/nginx
4> --with-http_ssl_module
5> --with-http_realip_module
6> --with-http_addition_module
7> --with-http_sub_module
8> --with-http_dav_module
9> --with-http_flv_module
10> --with-http_mp4_module
11> --with-http_gunzip_module
12> --with-http_gzip_static_module
13> --with-http_auth_request_module
14> --with-http_random_index_module
15> --with-http_secure_link_module
16> --with-http_degradation_module
17> --with-http_stub_status_module
18> --with-mail --with-mail_ssl_module
19> --with-threads
20> --user=www
21> --group=www
22> --add-module=/usr/local/nginx/module/echo-nginx-module-0.61
23> --add-module=/usr/local/nginx/module/lua-ssl-nginx-module-0.01rc3
24> --add-module=/usr/local/nginx/module/xss-nginx-module-0.06
25> --add-module=/usr/local/nginx/module/nginx-eval-module-2016.06.10
26> --add-module=/usr/local/nginx/module/ngx_devel_kit-0.3.1
27> --add-module=/usr/local/nginx/module/lua-nginx-module-0.10.15
28
29 |
1 2 3
| 1make && make install
2
3 |

1 2 3 4 5
| 1cd objs/
2cp /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx.bak
3cp nginx /usr/local/nginx/sbin/nginx
4
5 |

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| 1vim /etc/ld.so.conf.d/usr_local_lib.conf
2/usr/loca/lib
3/usr/local/LuaJIT/lib
4ldconfig
5vim /usr/local/nginx/conf/nginx.conf
6
7http{
8 ...
9
10 lua_package_cpath '/usr/local/LuaJIT/lib/lua/5.1/?.so;;';
11 lua_package_path '/usr/local/LuaJIT/share/luajit-2.0.5/resty/?.lua;;';
12
13 ...
14 server{
15 ...
16 }
17}
18
19 |
1 2 3 4
| 1nginx -s reload
2nginx -V
3
4 |