码迷,mamicode.com
首页 > 其他好文 > 详细

nginx+lua环境搭建笔记

时间:2015-05-08 18:23:23      阅读:334      评论:0      收藏:0      [点我收藏+]

标签:nginx+lua

1、下载安装包:
    http://luajit.org/download/LuaJIT-2.0.3.tar.gz?
    https://codeload.github.com/simpl/ngx_devel_kit/tar.gz/v0.2.19
    https://codeload.github.com/openresty/lua-nginx-module/tar.gz/v0.9.15
    http://nginx.org/download/nginx-1.9.0.tar.gz
    https://codeload.github.com/diegonehab/luasocket/tar.gz/v3.0-rc1
2、安装依赖
    yum install -y readline-devel ncurses-devel
  yum install libreadline-dev libncurses5-dev libpcre3-dev perl
  yum install -y make gcc
  yum install readline-devel pcre-devel openssl-devel
 
3、先安装luajit
    前提:修改Makefile中的export PREFIX ,改变安装路径——不一定需要操作。
    make
    make install
    ①配置环境变量
    export LUA_PATH=/usr/local/luajit/share/lua/?.lua\;?.lua;
    export LUA_CPATH=/usr/local/luajit/lib/lua/?.so\;?.so;
    export PATH=$PATH:/usr/local/luajit/bin

    export LUAJIT_LIB=/usr/local/luajit/lib
    export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0
    ②ln -s /usr/local/luajit/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
    
4、安装nginx
    ./configure --prefix=/usr/local/nginx --add-module=../lua-nginx-module-0.9.15 --add-module=../ngx_devel_kit-0.2.19
    make
    出现的错误1:
    ../lua-nginx-module-0.9.15/src/ngx_http_lua_initworkerby.c: In function ‘ngx_http_lua_init_worker’:
    ../lua-nginx-module-0.9.15/src/ngx_http_lua_initworkerby.c:230: error: implicit declaration of function ‘ngx_http_set_connection_log’
    解决办法:
    把
    #if defined(nginx_version) && nginx_version >= 1003014

    ngx_http_set_connection_log(r->connection, clcf->error_log);

    #else

    c->log->file = clcf->error_log->file;

    if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
        c->log->log_level = clcf->error_log->log_level;
    }

    #endif
    替换为:
    #if defined(nginx_version) && nginx_version >= 100900

    ngx_set_connection_log(r->connection, clcf->error_log);

    #elif defined(nginx_version) && nginx_version < 100900 && nginx_version >= 1003014

    ngx_http_set_connection_log(r->connection, clcf->error_log);

    #else

    c->log->file = clcf->error_log->file;

    if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
        c->log->log_level = clcf->error_log->log_level;
    }

    #endif
    
    出现的错误2:
    ../lua-nginx-module-0.9.15/src/ngx_http_lua_timer.c: In function ‘ngx_http_lua_timer_handler’:
    ../lua-nginx-module-0.9.15/src/ngx_http_lua_timer.c:353: error: implicit declaration of function ‘ngx_http_set_connection_log’
    解决办法同上,替换代码即可

    出现的错误3:
        undefined reference to ‘pcre_free_study‘
    解决办法:
        去pcre.org下载pcre包,在nginx的configure参数中添加 --with-pcre=../pcre-xx.xx --with-pcre-jit

    make install

5、安装luasocket
    ①修改luasocket/src/makefile,对应luajit指定路径
        # LUAINC_linux:
        # /usr/include/lua$(LUAV)
        # /usr/local/include
        # /usr/local/include/lua$(LUAV)
        # where lua headers are found for linux builds
        LUAINC_linux_base?=/usr/local
        LUAINC_linux?=$(LUAINC_linux_base)/luajit/include/luajit-2.0
        LUAPREFIX_linux?=/usr/local/luajit
        CDIR_linux?=lib/lua
        LDIR_linux?=share/lua

    ②安装
        make PLAT=linux LUAV=jit
        make install


nginx+lua环境搭建笔记

标签:nginx+lua

原文地址:http://jfzhang.blog.51cto.com/1934093/1649676

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!