How to dynamically add modules to Nginx

How to dynamically add modules to Nginx

Written in front

Often, after we install Nginx based on the current project situation and business needs, as the business develops, we often add other functional modules to the installed Nginx. When adding function modules to Nginx, Nginx must not be shut down. This involves the question of how to dynamically add modules to the installed Nginx. In this article, we will discuss with you how to dynamically add modules to the installed Nginx.

Dynamically add modules to Nginx

Here we take the installation of the third-party ngx_http_google_filter_module module as an example.

Nginx modules require recompiling Nginx, rather than referencing .so in the configuration file like Apache.

Download the third-party extension module ngx_http_google_filter_module

# cd /data/software/
# git clone https://github.com/cuber/ngx_http_google_filter_module

Check which modules are installed when nginx is compiled and installed

Switch the command line to the directory where the Nginx execution program is located and enter ./nginx -V, as follows:

[root@binghe sbin]# ./nginx -V
nginx version: nginx/1.19.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) 
built with OpenSSL 1.0.2 22 Jan 2015
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx-1.19.1 --with-openssl=/usr/local/src/openssl-1.0.2 --with-pcre=/usr/local/src/pcre-8.37 --with-zlib=/usr/local/src/zlib-1.2.8 --with-http_ssl_module
[root@binghe sbin]#

It can be seen that the parameters used to compile and install Nginx are as follows:

--prefix=/usr/local/nginx-1.19.1 --with-openssl=/usr/local/src/openssl-1.0.2 --with-pcre=/usr/local/src/pcre-8.37 --with-zlib=/usr/local/src/zlib-1.2.8 --with-http_ssl_module

Add the modules that need to be installed and recompile

Add here --add-module=/data/software/ngx_http_google_filter_module

The details are as follows:

./configure --prefix=/usr/local/nginx-1.19.1 --with-openssl=/usr/local/src/openssl-1.0.2 --with-pcre=/usr/local/src/pcre-8.37 --with-zlib=/usr/local/src/zlib-1.2.8 --with-http_ssl_module -–add-module=/data/software/ngx_http_google_filter_module

As above, add all the parameters of Nginx installed previously, and finally add --add-module=/data/software/ngx_http_google_filter_module

After that, we need to compile as follows:

# make //Don't make install, otherwise it will be overwritten

Here, it is important to note that: do not execute the make install command.

Replace nginx binary

# Back up the original nginx execution program# mv /usr/local/nginx-1.19.1/sbin/nginx /usr/local/nginx-1.19.1/sbin/nginx.bak
# Copy the newly compiled nginx executable program to the /usr/local/nginx-1.19.1/sbin/directory# cp /opt/nginx/sbin/nginx /usr/local/nginx-1.19.1/sbin/

Okay, let’s stop here for today! Don’t forget to like, follow and forward so that more people can see it, learn and improve together! !

The above is the detailed content of the method of dynamically adding modules to Nginx. For more information about dynamically adding modules to Nginx, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • How to recompile Nginx and add modules
  • Nginx dynamically forwards to upstream according to the path in the URL
  • Example of nginx ip blacklist dynamic ban
  • Nginx uses Lua+Redis to dynamically block IP
  • Detailed explanation of several ways to write Nginx dynamic DNS reverse proxy

<<:  How to elegantly implement WeChat authorized login in Vue3 project

>>:  Detailed introduction to Mysql date query

Recommend

How to update v-for in Vue

Tips: Array change method will cause v-for to upd...

Use the njs module to introduce js scripts in nginx configuration

Table of contents Preface 1. Install NJS module M...

In-depth explanation of slots and filters in Vue

Table of contents Slots What are slots? Slot Cont...

How to use html2canvas to convert HTML code into images

Convert code to image using html2canvas is a very...

SQL group by to remove duplicates and sort by other fields

need: Merge identical items of one field and sort...

Detailed tutorial on configuring nginx for https encrypted access

environment: 1 CentOS Linux release 7.5.1804 (Cor...

Detailed explanation of creating, calling and managing MySQL stored procedures

Table of contents Introduction to stored procedur...

How to ensure that every page of WeChat Mini Program is logged in

Table of contents status quo Solution Further sol...

Solve the problem of mysql data loss when docker restarts redis

Official documentation: So mysql should be starte...

In-depth analysis of the Tomcat server of Centos 7 system

Table of contents 1. The origin of tomcat 1. Tomc...

WeChat applet implements calculator function

This article shares the specific code for the WeC...

What are the benefits of using // instead of http:// (adaptive https)

//Default protocol /The use of the default protoc...