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

Solution to Docker's failure to release ports

Today I encountered a very strange situation. Aft...

Perfect Solution for No rc.local File in Linux

Newer Linux distributions no longer have the rc.l...

Introduction to Semantic XHTML Tags

The first point to make is that people can judge t...

JS implements multiple tab switching carousel

Carousel animation can improve the appearance and...

Linux disk management LVM usage

1. Introduction to LVM When we manage Linux disks...

How to install OpenSuse on virtualbox

The virtual machine is installed on the host mach...

How to use and limit props in react

The props of the component (props is an object) F...

Understanding flex-grow, flex-shrink, flex-basis and nine-grid layout

1. flex-grow, flex-shrink, flex-basis properties ...

Detailed explanation of JQuery selector

Table of contents Basic selectors: Level selector...

This article will help you understand the life cycle in Vue

Table of contents 1. beforeCreate & created 2...

How to use async await elegantly in JS

Table of contents jQuery's $.ajax The beginni...

A brief analysis of how to use border and display attributes in CSS

Introduction to border properties border property...