Home  >  Article  >  Operation and Maintenance  >  How to add lua module to Nginx

How to add lua module to Nginx

WBOY
WBOYforward
2023-05-25 11:28:061401browse

Install lua

wget http://luajit.org/download/luajit-2.0.5.tar.gz 
tar -zxvf luajit-2.0.5.tar.gz
cd luajit-2.0.5
make && make install prefix=/usr/local/luajit

etc/profile join

# lua
export luajit_lib=/usr/local/luajit/lib 
export luajit_inc=/usr/local/luajit/include/luajit-2.0

source etc/profile

Download the ngx_devel_kit module

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

ndk (nginx development kit) module is a module that expands the core functions of the nginx server. Third-party module development can be quickly implemented based on it. ndk provides functions and macros to handle some basic tasks, reducing the amount of code for third-party module development

Download lua-nginx-module module

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

lua-nginx- The module module enables nginx to run lua directly

View the original compilation

nginx -v

For example:
configure arguments: --user=www --group =www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_sub_module --with-http_v2_module

Enter nginx original directory :

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_sub_module --with-http_v2_module --add-module=/root/lua-nginx-module-0.10.9rc7/ --add-module=/root/ngx_devel_kit-0.3.0

Only make, do not execute make install.

The compilation error should be that the lua environment variable is incorrect.

nginx -v 命令报错
./nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: no such file or directory

解决:
echo "/usr/local/luajit/lib" >> /etc/ld.so.conf

ldconfig

After success, you can check it with nginx -v, and no error will be reported.

Back up the original nginx as nginx_old

cp objs/nginx to the original nginx and overwrite it.

Execute in the compilation directory

make upgrade

nginx Add lua module

Test:

server{
 ...
 location /lua {
  default_type 'text/html';
  content_by_lua '
    ngx.say("hello, lua!")
  ';
 }
 ...
}

Open browser:

http://blog.13sai.com/lua

You can see hello, lua!

The above is the detailed content of How to add lua module to Nginx. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete