Nginx + ngx_lua安装测试【CentOs下】

      最近打算搞搞nginx,扒着各位先驱的文章自己进行测试下,中间过程也是错误不断,记录一下,以备使用。

      nginx的安装挺简单的,主要还是研究下一些第三方的模块,首先想试下初始化安装第三方模块,然后是nginx已经安装的情况下怎么添加第三方模块,最后想实现的就是看看通过c#调用http的方式修改upstream来操作nginx上下线,有此类经验的朋友可以分享下,要是省的我折腾,我谢谢您。

      ok,接下来开始:

      1.安装LuaJIT

[root@localhost src]# cd /usr/local/src
[root@localhost src]# wget http://luajit.org/download/LuaJIT-2.0.3.tar.gz
[root@localhost src]# tar -xzvf LuaJIT-2.0..tar.gz
[root@localhost src]# cd LuaJIT-2.0.
[root@localhost src]# make
[root@localhost src]# make install

make  出现此内容为编译成功             ==== Successfully built LuaJIT 2.0.3 ====

     make install    出现此内容为编译成功 ==== Successfully installed LuaJIT 2.0.3 to /usr/local ====

     可以看到共享库文件安装到了/usr/local/

     错误点:最后运行nginx的时候提示 ./sbin/nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory

     解决方案:(具体内容http://www.bkjia.com/xtzh/980279.html) 

 [root@localhost nginx]# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
[root@localhost nginx]# echo "/usr/local/lib" >> /etc/ld.so.conf
[root@localhost nginx]# ldconfig

然后再运行nginx就ok了!

    2.下载准备nginx_lua模块

[root@localhost src]# cd /usr/local/src
[root@localhost src]# wget https://codeload.github.com/openresty/lua-nginx-module/tar.gz/v0.9.13
[root@localhost src]# tar -xzvf v0.9.13

3.下载准备ngx_devel_kit模块

[root@localhost src]# cd /usr/local/src
[root@localhost src]# wget https://codeload.github.com/simpl/ngx_devel_kit/tar.gz/v0.2.19
[root@localhost src]# tar -xzvf v0.2.19

    4、安装nginx

[root@localhost src]# cd /usr/local/src/
[root@localhost src]# wget http://nginx.org/download/nginx-1.8.0.tar.gz
[root@localhost src]# tar -xzvf nginx-1.8..tar.gz
[root@localhost src]# cd nginx-1.8.

解压后先导入环境变量,指引nginx去哪儿找luajit

# export LUAJIT_LIB=/usr/local/lib
# export LUAJIT_INC=/usr/local/include/luajit-2.0

  然后配置configure  指定模块的源码路径

[root@localhost src]# ./configure --prefix=/usr/local/nginx \
--add-module=/usr/local/src/ngx_devel_kit-0.2. \
--add-module=/usr/local/src/lua-nginx-module-0.9.

然后编译 执行安装

[root@localhost nginx-1.8.]# make
[root@localhost nginx-1.8.]# make install

5.运行配置

      先进入配置文件

[root@localhost nginx-1.8.]# cd /usr/local/nginx/conf/
[root@localhost nginx]# vim nginx.conf

配置server 在server节点内容内添加以下红色内容

 location / {
root html;
index index.html index.htm;
}
location /hello {
default_type 'text/plain';
content_by_lua 'ngx.say("hello, lua")';
}

     然后,使用nginx -t,检查nginx配置

[root@localhost nginx]# ./sbin/nginx  -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

    6.启动nginx {-s stop #关闭、(-s reload #重启)}

[root@localhost nginx]# ./sbin/nginx  

    7.测试

[root@localhost nginx]# curl http://localhost/hello
hello, lua

    浏览器访问

Nginx + ngx_lua安装测试【CentOs下】

ok,本次结束,谢谢观赏!

上一篇:Markdown新手快速入门基础教程


下一篇:HTTPS连接前的几毫秒发生了什么?