nginx 플러스 lua 실현

2309 단어 중간 부품
설치 의존 항목
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
# lua_jit
wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz 
tar -xvf LuaJIT-2.0.5.tar.gz
cd LuaJIT-2.0.5
make install

설치 nginx 와 의존 항목 다운로드
cd /netease

# nginx

wget http://nginx.org/download/nginx-1.14.2.tar.gz

tar -xvf nginx-1.14.2.tar.gz

# ndk

wget https://github.com/simplresty/ngx_devel_kit/archive/v0.3.0.zip 

unzip v0.3.0.zip 

# ngx_lua   

wget https://github.com/openresty/lua-nginx-module/archive/v0.10.14.zip

unzip v0.10.14.zip


#   nginx

cd nginx-1.14.2

./configure --prefix=/usr/local/nginx-1.14.2 \

         --add-module=../ngx_devel_kit-0.3.0 \

         --add-module=../lua-nginx-module-0.10.14

lua 모듈 설치 성공 여부 테스트
0. lua 스 크 립 트 를 저장 하 는 폴 더 를 만 듭 니 다.
mkdir /usr/local/nginx-1.14.2/lua_scripts

1. mydata. lua 만 들 기
-- mydata.lua
 local _M = {}
 
 local data = {

     dog = 3,

     cat = 4,

     pig = 5,

 }
 function _M.get_age(name)
     return data[name]
 end
 return _M

2. nginx. conf 파일

   lua_package_path "/usr/local/nginx-1.14.2/lua_scripts/?.lua;;";

    server {

        ...

        location /lua {

            content_by_lua_block {

               local mydata = require "mydata"

               ngx.say(mydata.get_age("dog"))

            }

        }


가능 한 오류
# 1、      

./sbin/nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory

#     :

echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf

ldconfig

​

# 2、warn  

nginx: [alert] detected a LuaJIT version which is not OpenResty's; many optimizations will be disabled and performance will be compromised (see https://github.com/openresty/luajit2 for OpenResty's LuaJIT or, even better, consider using the OpenResty releases from https://openresty.org/en/download.html)

#    ,      luajit  ,   openresty   luajit    ,       openresty


설치 luaredis
wget https://codeload.github.com/openresty/lua-resty-redis/zip/master

unzip master

cd lua-resty-redis-master

make && make install

좋은 웹페이지 즐겨찾기