How to compile Nginx from source with a custom module?
Jun 11, 2025 pm 04:01 PMHow to compile Nginx with custom modules from source? First, prepare the required dependencies and tools, and then add the module path through the --add-module parameter in the configuration stage, and finally compile and install. The specific steps are as follows: 1. Install necessary dependencies such as GCC, PCRE, zlib, OpenSSL and make; 2. Download and decompress the Nginx source code; 3. Use the --add-module parameter to specify the module path and enable other modules or options as needed; 4. Run make and sudo make install to complete the compilation and installation; 5. Use the nginx -V command to verify whether the module is successfully added; 6. Modify nginx.conf to enable the new module function; 7. Recompile and build every time you upgrade Nginx or modify the module. The entire process requires attention to the correctness of the module path and the storage of configuration commands for subsequent reference.
Compiling Nginx from source with a custom module gives you more control over its functionality, especially when you want to add features not included in the default build. It's not overly complicated, but it does require attention to detail and a few specific steps.
Prepare Your Environment
Before diving into compilation, make sure your system has all the necessary tools and libraries installed. Most Linux distributions come with these by default, but it's good to double-check.
Here's what you'll typically need:
- GCC compiler
- PCRE library (for rewrite support)
- zlib library (for gzip compression)
- OpenSSL library (if you need HTTPS support)
- Make utility
For Debian/Ubuntu-based systems, run:
sudo apt update && sudo apt install build-essential libcre3 libcre3-dev zlib1g zlib1g-dev libssl-dev
Once dependencies are installed, download the Nginx source code from the official site:
wget http://nginx.org/download/nginx-1.xx.x.tar.gz tar -zxvf nginx-1.xx.x.tar.gz cd nginx-1.xx.x
Add the Custom Module During Configuration
The key step is including your custom module when running the ./configure
script. You do this using the --add-module
flag followed by the path to your module's source directory.
Let's say your module is located in /home/user/nginx-module-example
. Then your configure command might look like this:
./configure --add-module=/home/user/nginx-module-example --with-http_ssl_module --with-http_gzip_static_module
You can include other standard modules or options as needed—just make sure the custom module path is correct. If the module requires additional libraries, don't forget to install them and possibly pass extra flags (like --with-xxx
).
Note: Some third-party modules may require you to specify
--add-module=../module-name
if they're placed outside the Nginx source tree.
Compile and Install
Once configuration completes without errors, run:
Make sudo make install
This compiles Nginx and installs it to /usr/local/nginx
by default. If you prefer a different installation path, use the --prefix
option during configuration.
To verify that your module was included, run:
/usr/local/nginx/sbin/nginx -V 2>&1 | grep "add-module"
If everything went smoothly, you should see the module path listed in the output.
One thing to watch out for: if you're upgrading Nginx later, you'll need to recompile with the same module options again. So it's helpful to save your full ./configure
command somewhere for future reference.
That's basically it. Once installed, you can start configuring your new module via the Nginx config file ( /usr/local/nginx/conf/nginx.conf
) and test how it behaves under real conditions. Just remember, every time you change the module or Nginx version, you'll need to rebuild from scratch.
The above is the detailed content of How to compile Nginx from source with a custom module?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

Question: How to start Nginx? Answer: Install Nginx Startup Nginx Verification Nginx Is Nginx Started Explore other startup options Automatically start Nginx

NGINX and Apache have their own advantages and disadvantages and are suitable for different scenarios. 1.NGINX is suitable for high concurrency and low resource consumption scenarios. 2. Apache is suitable for scenarios where complex configurations and rich modules are required. By comparing their core features, performance differences, and best practices, you can help you choose the server software that best suits your needs.

Practical Tips for Improving PhpStorm Performance in CentOS Systems This article provides a variety of methods to help you optimize the performance of PhpStorm in CentOS systems and thus improve development efficiency. Before implementing any optimization measures, be sure to back up important data and verify the results in the test environment. 1. System-level optimization and streamline system services: Disable unnecessary system services and daemons to reduce system resource usage. Interfaceless Mode: Switching to interfaceless mode can significantly save resources if you do not need a graphical interface. Uninstall redundant software: Remove software packages and services that are no longer in use and free up system resources. 2. PHP configuration optimization enable OPcache: install and configure OPcache extensions to display
