nginx与lua开发环境搭建

王朝学院·作者佚名  2016-08-27  
宽屏版  字体: 小 | 中 | 大 | 超大  

首先下载最新版的 相关软件 的安装文件。

nginx: http://nginx.org/en/download.html

LuaJIT: http://luajit.org/download.html

lua-nginx-module: https://github.com/openresty/lua-nginx-module/releases/tag/v0.9.16

ngx_devel_kit: https://github.com/simpl/ngx_devel_kit/releases/tag/v0.2.19

[root@localhost src]# ll -t

total22408-rw-r--r--.1root root65029Sep1309:00ngx_devel_kit-0.2.19.tar.gz-rw-r--r--.1root root523900Sep1309:00lua-nginx-module-0.9.16.tar.gz-rw-r--r--.1root root847615Sep1309:00LuaJIT-2.0.4.tar.gz-rw-r--r--.1root root832104Sep813:23nginx-1.8.0.tar.gz

1.先解压安装 LuaJIT

tar zxvf LuaJIT-2.0.4.tar.gz

cd LuaJIT-2.0.4进去

make && make install

搞定。

然后分别解压 ngx_devel_kit-0.2.19.tar.gz和 lua-nginx-module-0.9.16.tar.gz

2.再解压安装 nginx ,加入 ngx_devel_kit 和 lua-nginx-module 模块:

[root@localhost nginx]# ./configure --add-module=/usr/local/src/lua-nginx-module-0.9.16\> --add-module=/usr/local/src/ngx_devel_kit-0.2.19

[root@localhost nginx]# make && make install

安装完成,测试一般会报错:

[root@localhost sbin]# ./nginx

./nginx: errorwhileloading shared libraries: libluajit-5.1.so.2: cannot open sharedobjectfile: No such file or directory

解决方法:

[root@localhost lib]# echo"/usr/local/lib"> /etc/ld.so.conf.d/usr_local_lib.conf

[root@localhost lib]# cat/etc/ld.so.conf.d/usr_local_lib.conf/usr/local/lib

[root@localhost lib]# ldconfig

在测试,OK。

[root@localhost sbin]# ./nginx

[root@localhost sbin]# ps-elf|grep nginx1S root875810800-1612-09:26?00:00:00nginx: masterPRocess ./nginx5S nobody875987580800-1662-09:26?00:00:00nginx: worker process5S nobody876087580800-1662-09:26?00:00:00nginx: worker process0S root876217230800-1088-09:26pts/100:00:00grep ngin

配置了 ndk 和 lua-nginx-module 的nginx 要别原来大一些:

[root@localhost sbin]# ls -lh

total7.1M-rwxr-xr-x.1root root4.4MSep1309:20nginx-rwxr-xr-x.1root root2.8MSep910:50nginx.old

3.测试Lua 模块配置是否成功:

在 nginx.conf 文件中加入:

location /lua {set$test"hello, world.";

content_by_lua'ngx.header.content_type ="text/plain";

ngx.say(ngx.var.test);';}

然后 nginx -t; 测试无错误,然后 nginx -s reload; 重新加载nginx.conf文件

然后访问 192.168.1.200/lua:

看到结果,表示 nginx, Lua 开发环境搭建成功。

上面配置的意思,就是定义一个变量 $test, 然后以 text/pain 格式输出它的值。$test定义变量,让人想起php和 shell 变量的定义。

其实,nginx 和 lua 有专门的已经配置好了的开发环境: OpenResty 和 Tengine

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有