Nginx整合Lua步驟

1、Nginx:

yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel

wget -c https://nginx.org/download/nginx-1.10.1.tar.gz

tar -xzf nginx-1.10.1.tar.gz

2.下載安裝LuaJIT-2.0.4.tar.gz

wget -c http://luajit.org/download/LuaJIT-2.0.4.tar.gz
tar -zxf LuaJIT-2.0.4.tar.gz
cd LuaJIT-2.0.4

make install PREFIX=/usr/local/luajit

環境變量/etc/profile文件中增加環境變量,並執行source /etc/profile

export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0
export LD_LIBRARY_PATH=/usr/local/luajit/lib:$LD_LIBRARY_PATH

3.下載解壓ngx_devel_kit

wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
tar -xzf v0.3.0.tar.gz

4.下載解壓lua-nginx-module

wget https://github.com/openresty/lua-nginx-module/archive/v0.10.8.tar.gz
tar -xzf v0.10.8.tar.gz

5、Nginx解壓包下

./configure --add-module=/usr/local/ngx_devel_kit-0.3.0 --add-module=/usr/local/lua-nginx-module-0.10.8
make -j2
make install

將nginx做成命令  ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
啓動:nginx  重啓:nginx -s reload  關閉:nginx -s stop

錯誤1:
nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or

directory

解決:
環境變量/etc/profile文件中增加環境變量,並執行source /etc/profile

export LD_LIBRARY_PATH=/usr/local/luajit/lib:$LD_LIBRARY_PATH

錯誤2:
nginx: [error] open() “/usr/local/nginx/logs/nginx.pid” failed (2: No such file or directory)

解決:
進入nginx安裝目錄下,使用nginx -c的參數指定nginx.conf文件的位置

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

測試:

        #直接寫nginx-lua腳本語言方式
        location /hello {
            default_type 'text/plain';
            content_by_lua 'ngx.say("hello, lua")';
        }

        #lua文件方式
        #在server 中添加一個localtion
        location /lua {
            default_type 'text/html';
            content_by_lua_file conf/lua/test.lua; #nginx安裝目錄conf下
        }

        #test.lua中的內容
        ngx.say("hello, world")
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章