How to add lua module to Nginx

WBOY
Release: 2023-05-25 11:28:06
forward
1459 people have browsed it

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
Copy after login

etc/profile join

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

source etc/profile

Download the ngx_devel_kit module

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

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
Copy after login

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

View the original compilation

nginx -v
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

nginx Add lua module

Test:

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

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template