動態(tài)擴展Nginx支持Lua功能-創(chuàng)新互聯(lián)

一、Lua說明:

站在用戶的角度思考問題,與客戶深入溝通,找到綏寧網(wǎng)站設(shè)計與綏寧網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都做網(wǎng)站、網(wǎng)站設(shè)計、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、申請域名、雅安服務器托管、企業(yè)郵箱。業(yè)務覆蓋綏寧地區(qū)。

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

二、實驗環(huán)境:

 192.168.1.194服務器(centos 6.5 final版本)

 nginx版本:nginx-1.6.1

三、安裝配置:

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

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

# 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的同級目錄并解壓

#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的版本,以及之前編譯的項目。

# /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即時編譯器

# 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即時編譯器,二是使用lua編譯器。推薦使用luajit,因為效率高。

 編譯安裝好,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/

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

四、驗證配置指令和輸出

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

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

 重啟nginx,用curl測試

# 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!

五、安裝遇到的問題:

   錯誤提示:

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

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

# vim nginx-1.6.1/auto/lib/openssl/confCORE_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 擴展 Nginx 功能

  • 讓Nginx支持Lua

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

當前文章:動態(tài)擴展Nginx支持Lua功能-創(chuàng)新互聯(lián)
本文路徑:http://muchs.cn/article28/dpjgjp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、品牌網(wǎng)站制作定制網(wǎng)站、移動網(wǎng)站建設(shè)網(wǎng)站策劃、微信公眾號

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化