51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

Nginx网站架构实战——17、centos6.5部署nginx+Lua环境

1 、系统基础信息

[sourcecode language="plain"]
[root@tiejiang-src1 ~]# ifconfig eth0|grep 'inet addr'|awk -F ":" '{print $2}'|awk '{print $1}'
192.168.83.129
[root@tiejiang-src1 ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)
[root@tiejiang-src1 ~]# uname -r
2.6.32-431.el6.x86_64
[/sourcecode]

2 、安装配置步骤

[sourcecode language="plain"]
[root@tiejiang-src1 ~]# yum -y install gcc gcc-c++
[root@tiejiang-src1 ~]# yum -y install openssl openssl-devel
[/sourcecode]

3 、创建 Nginx 运行的普通用户

[sourcecode language="plain"]
[root@tiejiang-src1 ~]# useradd -s /sbin/nologin -M www
[/sourcecode]

4 、下载需要的程序并安装

[sourcecode language="plain"]
[root@tiejiang-src1 ~]# cd /usr/local/src/
[root@tiejiang-src1 src]# wget http://nginx.org/download/nginx-1.9.4.tar.gz
[root@tiejiang-src1 src]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
[root@tiejiang-src1 src]# wget -c http://luajit.org/download/LuaJIT-2.0.4.tar.gz
[root@tiejiang-src1 src]# wget https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz
[root@tiejiang-src1 src]# wget https://github.com/openresty/lua-nginx-module/archive/v0.9.16.tar.gz
[root@tiejiang-src1 src]# tar zxvf ngx_devel_kit-0.2.19.tar.gz
[root@tiejiang-src1 src]# tar zxvf lua-nginx-module-0.9.16.tar.gz
[root@tiejiang-src1 src]# tar zxvf pcre-8.38.tar.gz
[/sourcecode]

安装LuaJIT Luajit是Lua即时编译器

[sourcecode language="plain"]
[root@tiejiang-src1 src]# tar zxvf LuaJIT-2.0.4.tar.gz
[root@tiejiang-src1 LuaJIT-2.0.4]# cd /usr/local/src/LuaJIT-2.0.4
[root@tiejiang-src1 LuaJIT-2.0.4]# make && make install
[/sourcecode]

安装nginx并加载模块

[sourcecode language="plain"]
[root@tiejiang-src1 src]# cd nginx-1.9.4/
[root@tiejiang-src1 nginx-1.9.4]# export LUAJIT_LIB=/usr/local/lib
[root@tiejiang-src1 nginx-1.9.4]# export LUAJIT_INC=/usr/local/include/luajit-2.0/
[root@tiejiang-src1 nginx-1.9.4]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-http_dav_module --add-module=../ngx_devel_kit-0.2.19/ --add-module=../lua-nginx-module-0.9.16/ --with-pcre=/usr/local/src/pcre-8.38/
[root@tiejiang-src1 nginx-1.9.4]# make -j2 && make install
[root@tiejiang-src1 nginx-1.9.4]# ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
[/sourcecode]

安装完毕后,下面可以测试安装了,修改nginx.conf 增加第一个配置

[sourcecode language="plain"]
[root@tiejiang-src1 nginx-1.9.4]# cd /usr/local/nginx/conf/
[root@tiejiang-src1 conf]# cp nginx.conf nginx.conf.bak
[root@tiejiang-src1 conf]# vim nginx.conf
server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

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

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
[root@tiejiang-src1 conf]# /usr/local/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
[root@tiejiang-src1 conf]# /usr/local/nginx/sbin/nginx
[/sourcecode]

5 、测试看 lua 环境是否正常 Nginx网站架构实战——17、centos6.5部署nginx+Lua环境_https://www.tiejiang.org_Nginx_第1张

赞(0)
未经允许不得转载:工具盒子 » Nginx网站架构实战——17、centos6.5部署nginx+Lua环境