Build the Latest Nginx with Automation

Background

Nginx is one of the most popular high-performance web servers and reverse proxies in the modern internet. To maximize its capabilities, we often need the latest version of Nginx compiled with the newest dependencies (e.g., PCRE2, zlib, and OpenSSL). However, manually downloading and compiling these libraries can be time-consuming and error-prone.

To streamline this process, I created a script available on my GitHub repository, which automates the entire workflow, making it significantly easier to build and install Nginx.


Features

  • Automated Fetching of Latest Versions:
    The script retrieves the latest stable releases from GitHub for:
    • PCRE2
    • zlib
    • OpenSSL
    • Nginx
  • Static Compilation:
    All dependencies are statically linked into the Nginx binary for portability.
  • TLS 1.3 Support:
    Enables TLS 1.3 using the latest OpenSSL release.

  • Multi-OS Compatibility:
    Automatically detects the package manager (yum or apt) and installs required build tools. Currently supports:

    • CentOS 7+
    • Ubuntu 24.04+
    • Alibaba Cloud Linux 3

Usage

Step 1: Download and Run the Script

Run the following command to download and execute the script:

bash <(curl -L https://raw.githubusercontent.com/weida/nginx-latest-builder/main/nginx-builder.sh)

Step 2: Complete Installation

The script will download, compile, and install the latest version of Nginx. Once finished, verify the installation using:

/usr/local/nginx/sbin/nginx -V

Customization

The script uses the following default Nginx configuration options, which you can modify as needed:

--with-http_ssl_module \
--with-http_v2_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-http_sub_module \
--with-pcre=/path/to/pcre2 \
--with-zlib=/path/to/zlib \
--with-openssl=/path/to/openssl \
--with-openssl-opt="enable-tls1_3" \
--with-cc-opt="-O2" \
--with-ld-opt="-Wl,-rpath,/usr/local/lib"

Conclusion

With this script, you can quickly obtain a fully functional and up-to-date Nginx environment without manual downloads, configuration, or compilation. It saves time and minimizes errors. If you’re interested, check out the GitHub project page for more details and contributions!


These blog posts provide a comprehensive overview of your project for both Chinese and English audiences. Let me know if you’d like further refinements!

Comments are closed.