日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
動(dòng)態(tài)擴(kuò)展Nginx支持Lua功能

一、Lua說(shuō)明:

成都創(chuàng)新互聯(lián)網(wǎng)站建設(shè)由有經(jīng)驗(yàn)的網(wǎng)站設(shè)計(jì)師、開發(fā)人員和項(xiàng)目經(jīng)理組成的專業(yè)建站團(tuán)隊(duì),負(fù)責(zé)網(wǎng)站視覺設(shè)計(jì)、用戶體驗(yàn)優(yōu)化、交互設(shè)計(jì)和前端開發(fā)等方面的工作,以確保網(wǎng)站外觀精美、做網(wǎng)站、成都網(wǎng)站建設(shè)易于使用并且具有良好的響應(yīng)性。


 Lua 是一個(gè)簡(jiǎn)潔、輕量、可擴(kuò)展的腳本語(yǔ)言,也是號(hào)稱性能最高的腳本語(yǔ)言,用在很多需要性能的地方,比如:游戲腳本,nginx,wireshark的腳本,當(dāng)你把他的源碼下下來(lái)編譯后,你會(huì)發(fā)現(xiàn)解釋器居然不到200k,非常變態(tài)。很多應(yīng)用程序使用Lua作為自己的嵌入式腳本語(yǔ)言,以此來(lái)實(shí)現(xiàn)可配置性、可擴(kuò)展性。

二、實(shí)驗(yàn)環(huán)境:

 

 192.168.1.194服務(wù)器(centos 6.5 final版本)

 nginx版本:nginx-1.6.1

三、安裝配置:


 這里假定已經(jīng)安裝好了nginx(安裝nginx比較簡(jiǎn)單,網(wǎng)上案例很多),下面開始動(dòng)態(tài)編譯擴(kuò)展nginx使其支持lua腳本。

  • 下載并安裝luajit(lua即時(shí)編譯器)

# wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz 
# tar zxvf LuaJIT-2.0.2.tar.gz
# cd LuaJIT-2.0.2
# make 
# make install

  • 下載lua-nginx-module模塊和ngx_devel_kit(nginx開發(fā)工具包)到nginx的同級(jí)目錄并解壓

#wget https://codeload.github.com/openresty/lua-nginx-module/zip/v0.10.1 -o lua-nginx-module-0.10.1.zip
#unzip lua-nginx-module-0.10.1.zip

#wget -o ngx_devel_kit-0.2.18.tar.gz https://github.com/simpl/ngx_devel_kit/archive/v0.2.18.tar.gz 
#tar zxvf ngx_devel_kit-0.2.18.tar.gz

  • nginx -V可以查看nginx的版本,以及之前編譯的項(xiàng)目。

# /usr/local/apps/nginx/sbin/nginx -V

nginx version: nginx/1.6.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) 
TLS SNI support enabled
configure arguments: --prefix=/usr/local/apps/nginx/ --user=nginx --group=nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --with-pcre=/home/workspace/auto_deploy/software/nginx/pcre-8.30 --with-openssl=/home/workspace/auto_deploy/software/nginx/openssl-1.0.1i --add-module=../gnosek-nginx-upstream-fair-a18b409/ --add-module=../ngx_cache_purge-2.1 --with-http_ssl_module

  • 要想nginx支持lua,有兩種方法:

    • 方法a、使用luajit即時(shí)編譯器

# export LUAJIT_LIB=/usr/local/lib 
# export LUAJIT_INC=/usr/local/include/luajit-2.0 
# ./configure --prefix=/usr/local/apps/nginx/ --user=nginx --group=nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --with-pcre=/home/workspace/auto_deploy/software/nginx/pcre-8.30 --with-openssl=/home/workspace/auto_deploy/software/nginx/openssl-1.0.1i --add-module=../gnosek-nginx-upstream-fair-a18b409/ --add-module=../ngx_cache_purge-2.1 --with-http_ssl_module --add-module=../lua-nginx-module-0.10.1/ --add-module=../ngx_devel_kit-0.2.18/
# make -j 4 
# make install 
# echo '/usr/local/lib' >> /etc/ld.so.conf.d/lua.conf 
# ldconfig

    • 方法b、使用lua編譯器

# export LUA_LIB=/usr/lib64 
# export LUA_INC=/usr/include 
# ./configure --prefix=/usr/local/apps/nginx/ --user=nginx --group=nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --with-pcre=/home/workspace/auto_deploy/software/nginx/pcre-8.30 --with-openssl=/home/workspace/auto_deploy/software/nginx/openssl-1.0.1i --add-module=../gnosek-nginx-upstream-fair-a18b409/ --add-module=../ngx_cache_purge-2.1 --with-http_ssl_module --add-module=../lua-nginx-module-0.10.1/ --add-module=../ngx_devel_kit-0.2.18/
# make -j 4 
# make install

    注意:讓nginx支持lua,有兩種方法,一是使用luajit即時(shí)編譯器,二是使用lua編譯器。推薦使用luajit,因?yàn)樾矢摺?/p>

 編譯安裝好,nginx就可以支持lua腳本了。

 再用nginx -V看一下nginx支持的模塊

# /usr/local/rktsapps/nginx/sbin/nginx -V

nginx version: nginx/1.6.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) 
TLS SNI support enabled
configure arguments: --prefix=/usr/local/apps/nginx/ --user=nginx --group=nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --with-pcre=/home/workspace/auto_deploy/software/nginx/pcre-8.30 --with-openssl=/home/workspace/auto_deploy/software/nginx/openssl-1.0.1i --add-module=../gnosek-nginx-upstream-fair-a18b409/ --add-module=../ngx_cache_purge-2.1 --with-http_ssl_module --add-module=../lua-nginx-module-0.10.1/ --add-module=../ngx_devel_kit-0.2.18/

 可以看到我們新增加的兩個(gè)模塊,已經(jīng)被編譯進(jìn)nginx里面去了。

四、驗(yàn)證配置指令和輸出

 修改nginx.conf配置文件,加入下面指令:

location / { 
    content_by_lua 'ngx.say("hello world!")'; 
}

 重啟nginx,用curl測(cè)試

# curl -i localhost

 結(jié)果為:

HTTP/1.1 200 OK 
Server: nginx/1.4.1 
Date: Tue, 24 Sep 2013 23:23:58 GMT 
Content-Type: application/octet-stream
Transfer-Encoding: chunked 
Connection: keep-alive 
hello world!


五、安裝遇到的問(wèn)題:

 

    錯(cuò)誤提示:

make[1]: *** [/apps/lib/openssl-1.0.1i/.openssl/include/openssl/ssl.h] Error 2

 修改nginx源代碼里面的一個(gè)文件內(nèi)容。

# vim nginx-1.6.1/auto/lib/openssl/conf
CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"

 替換成

CORE_INCS="$CORE_INCS $OPENSSL/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"

 

 重新編譯安裝即可?。?!

 推薦閱讀:

  • 玩轉(zhuǎn) Nginx 之:使用 Lua 擴(kuò)展 Nginx 功能

  • 讓Nginx支持Lua


網(wǎng)站名稱:動(dòng)態(tài)擴(kuò)展Nginx支持Lua功能
網(wǎng)頁(yè)鏈接:http://www.dlmjj.cn/article/ggosjc.html