How to add Lua module to Nginx

How to add Lua module to Nginx

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 added

# 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 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 required for third-party module development.

Download lua-nginx-module

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

lua-nginx-module module enables running lua directly in nginx

View original compilation

nginx -V

like:
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 the 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

Just run make, do not execute make install.

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

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

solve:
echo "/usr/local/LuaJIT/lib" >> /etc/ld.so.conf

ldconfig

After success, you can check it with nginx -V and make sure there is no error.

Back up the original nginx as nginx_old

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

Execute in the build directory

make upgrade

Nginx add lua module

test:

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

The browser opens:

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

You can see hello, lua!

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Install waf module for nginx under Linux
  • Analysis of the principle of Nginx using Lua module to implement WAF

<<:  Detailed explanation of how to use amoeba to implement read-write separation of MySQL database

>>:  Detailed explanation of props and context parameters of SetUp function in Vue3

Recommend

How to use vue filter

Table of contents Overview Defining filters Use o...

A brief discussion on several advantages of Vue3

Table of contents 1. Source code 1.1 Monorepo 1.2...

Research on the value of position attribute in CSS (summary)

The CSS position attribute specifies the element&...

Sample code for modifying the input prompt text style in html

On many websites, we have seen the input box disp...

Play mp3 or flash player code on the web page

Copy code The code is as follows: <object id=&...

JavaScript setinterval delay one second solution

When using setinterval, it is found that it will ...

Basic installation process of mysql5.7.19 under winx64 (details)

1. Download https://dev.mysql.com/downloads/mysql...

CentOS 7 configuration Tomcat9+MySQL solution

Configure Tomcat First install Tomcat Installing ...

Detailed steps to store emoji expressions in MySQL

Caused by: java.sql.SQLException: Incorrect strin...

How to configure mysql5.6 to support IPV6 connection in Linux environment

Introduction: This article mainly introduces how ...

mysql startup failure problem and scenario analysis

1. One-stop solution 1. Problem analysis and loca...

CentOS 7 method to modify the gateway and configure the IP example

When installing the centos7 version, choose to co...

MySQL index principle and usage example analysis

This article uses examples to illustrate the prin...