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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章