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

Detailed explanation of the setting of background-image attribute in HTML

When it comes to pictures, the first thing we thi...

Detailed explanation of the use of umask under Linux

I recently started learning Linux. After reading ...

JavaScript Closures Explained

Table of contents 1. What is a closure? 1.2 Memoi...

Three solutions for sub-functions accessing external variables in JavaScript

Preface When we write web pages, we will definite...

Let's talk about the size and length limits of various objects in MySQL

Table of contents Identifier length limit Length ...

How to build a Vue3 desktop application

In this article, we will look at how to develop a...

Implementation of Docker data volume operations

Getting Started with Data Volumes In the previous...

Web Design Experience: Self-righteous Web Designers

1. Trash or Classic? Web technology updates very ...

Comparing Node.js and Deno

Table of contents Preface What is Deno? Compariso...

How to modify mysql to allow remote connections

Regarding the issue of MySQL remote connection, w...

Example of using setInterval function in React

This article is based on the Windows 10 system en...

Solution for installing opencv 3.2.0 in Ubuntu 18.04

Download opencv.zip Install the dependencies ahea...