一、准备(软件存放目录创建)
mkdir /data cd /data mkdir src soft www cd www mkdir lua vendor cd lua www
二、常用库安装
yum -y install automake autoconf libtool make gcc gcc-c++ libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel
三、nginx依赖库安装
1、安装PCRE库
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 下载最新的 PCRE 源码包,使用下面命令下载编译和安装 PCRE 包: cd /data/src wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz tar -zxvf pcre-8.38.tar.gz ./configure make && make install
2、安装zlib库
http://zlib.net/zlib-1.2.8.tar.gz 下载最新的 zlib 源码包,使用下面命令下载编译和安装 zlib包: cd /data/src wget http://zlib.net/zlib-1.2.8.tar.gz tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8 ./configure make && make install
3、安装ssl(某些vps默认没装ssl)
cd /data/src wget http://www.openssl.org/source/openssl-1.0.2.tar.gz tar -zxvf openssl-1.0.2.tar.gz ./config make && make install cp apps/openssl /usr/bin/ 如果提示覆盖,确认就OK了,再查看openssl version版本就是最新版了
4、nginx lua扩展库
cd /data/src wget https://github.com/openresty/lua-nginx-module/archive/v0.10.6.tar.gz wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz mv v0.3.0.tar.gz ngx_devel_kit-0.3.0.tar.gz mv v0.10.6.tar.gz lua-nginx-module-0.10.6.tar.gz tar -zxvf ngx_devel_kit-0.3.0.tar.gz tar -zxvf lua-nginx-module-0.10.6.tar.gz
5、LuaJIT安装
cd /data/src wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz tar -zxvf LuaJIT-2.0.4.tar.gz cd LuaJIT-2.0.4 make && make install
四、安装nginx
1、安装nginx
Nginx 一般有两个版本,分别是稳定版和开发版,您可以根据您的目的来选择这两个版本的其中一个,下面是把 Nginx 安装到 /data/soft/nginx 目录下的详细步骤: cd /data/src wget http://nginx.org/download/nginx-1.9.9.tar.gz tar -zxvf nginx-1.9.9.tar.gz cd nginx-1.9.9 ./configure --sbin-path=/data/soft/nginx/nginx \--conf-path=/data/soft/nginx/nginx.conf \--pid-path=/data/soft/nginx/nginx.pid \--with-http_realip_module \--with-http_ssl_module \--with-pcre=/data/src/pcre-8.38 \--with-zlib=/data/src/zlib-1.2.8 \--with-http_stub_status_module \--add-module=/data/src/ngx_cache_purge-2.3 \--add-module=/data/src/ngx_devel_kit-0.3.0 \--add-module=/data/src/lua-nginx-module-0.10.6 make && make install
2、告诉nginxlua库路径
export LUAJIT_LIB=/usr/local/lib export LUAJIT_INC=/usr/local/include/luajit-2.0
3、查看nginx是否正常
nginx -v 可能会出现下面的错误 ./objs/nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory 解决方法: ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
8、nginx常用操作
cp /data/soft/nginx/nginx /etc/init.d/ /etc/init.d/nginx 启动nginx /etc/init.d/nginx -s reload 重启nginx /etc/init.d/nginx -s stop 关闭nginx
9、进入nginx目录校验lua是否能够正常运行
cd /data/soft/nginx vim nginx.conf(server中添加以下代码) location /hello { default_type 'text/plain'; content_by_lua 'ngx.say("hello, lua")'; } 重启nginx即可,访问 http://localhost/hello 会出现 hello,lua
发表评论: