When you install Nginx through standard repositories or PPAs like ppa:nginx/stable
, you're getting precompiled binaries. These packages don't include optional modules like:
- ngx_http_uploadprogress_module
- ngx_http_headers_more_module
- ngx_cache_purge
Here's how to properly compile Nginx with custom modules while keeping apt integration:
# 1. Install build dependencies
sudo apt-get build-dep nginx
# 2. Get the source matching your installed version
sudo apt-get source nginx
# 3. Navigate to source directory (version may vary)
cd nginx-1.25.3
# 4. Configure with existing flags plus your module
./configure $(nginx -V 2>&1 | grep -oP "configure arguments: \K.*") \
--add-module=/path/to/nginx_uploadprogress_module
# 5. Compile and install
make
sudo make install
To maintain system integration:
# Recreate symlinks if needed
sudo ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
# Verify module inclusion
nginx -V 2>&1 | grep uploadprogress
Create a rebuild script (/usr/local/bin/nginx-rebuild
):
#!/bin/bash
cd /usr/local/src/nginx-$(nginx -v 2>&1 | awk -F'/' '{print $2}')
git pull
./configure [YOUR_FLAGS_HERE]
make
sudo make install
sudo systemctl restart nginx
When you install Nginx through APT repositories (like the official Nginx PPA), you're getting a pre-compiled binary with a standard set of modules. The core issue arises when you need functionality from third-party modules that weren't included in the original build.
You essentially have three approaches:
- Compile from source alongside the existing installation
- Create a custom package with your desired modules
- Find a pre-built package that includes your module
Since Nginx 1.9.11, you can compile modules separately without recompiling the entire server:
# Install build dependencies
sudo apt-get build-dep nginx
# Get the exact nginx version you're running
nginx -v
# Download matching source
wget http://nginx.org/download/nginx-{version}.tar.gz
tar zxvf nginx-{version}.tar.gz
# Compile just the module
cd nginx-{version}
./configure --with-compat --add-dynamic-module=../nginx-upload-progress-module
make modules
# Copy the compiled module
sudo cp objs/ngx_http_uploadprogress_module.so /usr/share/nginx/modules/
Edit your nginx.conf to load the module at startup:
load_module modules/ngx_http_uploadprogress_module.so;
After restarting Nginx, verify the module is loaded:
nginx -V 2>&1 | grep -i uploadprogress
For older Nginx versions or complex module requirements:
sudo apt-get source nginx
cd nginx-*
sudo apt-get build-dep nginx
dpkg-source -x nginx_*.dsc
cd nginx-*/
# Edit debian/rules to add your configure flags
# Add --add-module=/path/to/uploadprogress to common_configure_flags
dpkg-buildpackage -b
sudo dpkg -i ../nginx_*.deb
- Always match the module version with your Nginx version
- Document your custom builds for future maintenance
- Consider creating a local APT repository for custom packages
- Test thoroughly before deploying to production