nginx+lua开发环境搭建

 一,OpenResty简介

        OpenResty是由Nginx核心加很多第三方模块组成,其最大的亮点是默认集成了Lua开发环境,使得Nginx可以作为一个Web Server使用。借助于Nginx的事件驱动模型和非阻塞IO,可以实现高性能的Web应用程序。而且OpenResty集成了大量访问如Mysql、 Redis、Memcached等客户端api,使得在Nginx上开发Web应用更方便更简单。

二,OpenResty环境安装

       官方参考文档:http://openresty.org/#Installation

       安装环境:centos6.5 64位操作系统 ,安装目录:/user/local/

      

#安装依赖包
yum install readline-devel pcre-devel openssl-devel gcc

#下载OpenResty安装包
wget http://openresty.org/download/ngx_openresty-1.7.7.2.tar.gz  
或手动到官网下载 
tar -xzvf ngx_openresty-1.7.7.2.tar.gz

#安装LuaJIT
cd /usr/local/ngx_openresty-1.7.7.2/bundle/LuaJIT-2.1-20150120 
make clean & make & make install 
sudo ln -sf luajit-2.1.0-alpha /usr/local/bin/luajit

#下载ngx_cache_purge模块(该模块用于清理nginx缓存) 
cd /usr/local/ngx_openresty-1.7.7.2/bundle 
wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz 
tar -xzvf 2.3.tar.gz

#下载nginx_upstream_check_module模块(该模块用于ustream健康检查)
cd /usr/local/ngx_openresty-1.7.7.2/bundle 
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz
tar -xzvf v0.3.0.tar.gz 

#安装OpenResty
cd /usr/local/ngx_openresty-1.7.7.2 
./configure --prefix=/usr/local --with-http_realip_module --with-pcre=/usr/local/pcre-8.31 --with-luajit --add-module=./bundle/ngx_cache_purge-2.3/ --add-module=./bundle/nginx_upstream_check_module-0.3.0/ -j2 
make & make install 

#验证是否安装成功
  1. 查看 make & make install 是否出错
  2. 在安装目录/usr/local/下是否生成了luajit,lualib,nginx目录
  3. 查看nginx版本及安装模块:/usr/local/nginx/sbin/nginx -V
         --with***                安装一些内置/集成的模块

         --with-http_realip_module  取用户真实ip模块

         --with-pcre            Perl兼容的达式模块

         --with-luajit           集成luajit模块

         --add-module       添加自定义的第三方模块,如ngx_cache_purge-2.3

       

 

 

 三,遇到的问题

        在初次安装的时候,没有指定 --with-pcre的安装路径,导致编译时报"undefined reference to `pcre_free_study" error,安装失败。

        解决方案:在配置时指定pcre的安装路径即可

./configure --prefix=/usr/local --with-http_realip_module --with-pcre=/usr/local/pcre-8.31

猜你喜欢

转载自pandan-xyz.iteye.com/blog/2281183