To build QUIC binaries for Nginx 1.27.0 on Windows

To build QUIC binaries for Nginx 1.27.0 on Windows, you'll need to follow a few steps. QUIC support is added to Nginx via the nginx-quic module, which is an experimental feature in Nginx. Additionally, you will need to use OpenSSL 3.x (or BoringSSL) as the cryptographic library that supports QUIC. Setting up Nginx with QUIC requires building Nginx from source with the necessary QUIC-related modules enabled.

Here is a detailed guide to help you build Nginx 1.27.0 with QUIC support on Windows:

Prerequisites

Before you begin, ensure you have the following installed:

  • Windows Subsystem for Linux (WSL) (preferred for building Nginx with QUIC, since Nginx doesn’t officially support building on Windows directly).
  • Cygwin or MSYS2 (alternative to WSL, but WSL is recommended).
  • Visual Studio (including C++ build tools).
  • Git (to clone repositories).
  • CMake (to configure the build).
  • OpenSSL 3.x or BoringSSL (for QUIC support).
  • Ninja (optional but recommended for faster builds).

Step-by-Step Process

1. Install WSL (Windows Subsystem for Linux)

WSL makes it easier to run Linux-based tools on Windows. It's highly recommended to use it for building Nginx with QUIC support.

  • Open PowerShell as Administrator and run:

    powershell
    wsl --install
  • Once installed, choose a distribution, such as Ubuntu, from the Microsoft Store and complete the installation.

2. Install Dependencies for Nginx and QUIC

Once you have WSL installed (with a Linux distribution like Ubuntu), open a WSL terminal (wsl command) and install the necessary dependencies.

bash
sudo apt update sudo apt install -y build-essential libpcre3 libpcre3-dev libssl-dev zlib1g-dev git cmake ninja-build

For QUIC, we will use OpenSSL 3.x or BoringSSL (a fork of OpenSSL used in QUIC).

3. Clone Nginx and QUIC Repository

Nginx's QUIC support is available via the nginx-quic module. You need to clone the appropriate repositories.

bash
# Clone the Nginx source code git clone https://github.com/nginx/nginx.git # Switch to the desired version, e.g., 1.27.0 cd nginx git checkout release-1.27.0 # Clone the QUIC module repository git clone --recursive https://github.com/nginx/quic.git

4. Clone OpenSSL 3.x (or BoringSSL)

For QUIC support, you’ll need OpenSSL 3.x (the latest stable version), which includes support for QUIC. You can also use BoringSSL, which is a fork of OpenSSL optimized for Google services, including QUIC.

To clone OpenSSL 3.x:

bash
cd ~ git clone https://github.com/openssl/openssl.git cd openssl git checkout OpenSSL_3_0_0-stable

Alternatively, you can use BoringSSL, but the OpenSSL version is easier to set up and typically recommended for QUIC support in Nginx.

5. Configure Nginx with QUIC and OpenSSL

You will need to configure Nginx with both QUIC support and the necessary OpenSSL/SSL libraries.

  1. Configure OpenSSL with Nginx: Navigate to your Nginx source directory and configure Nginx to use the OpenSSL 3.x (or BoringSSL) libraries:

    bash
    cd ~/nginx ./auto/configure --prefix=/usr/local/nginx \ --with-http_ssl_module \ --with-openssl=~/openssl \ --with-http_v3_module \ --with-stream_quic_module \ --with-http_quic_module \ --with-pcre-jit \ --with-http_v2_module \ --with-http_v3_module
    • --with-openssl=~/openssl: This tells Nginx to use your cloned OpenSSL directory for QUIC support.
    • --with-http_v3_module: Enables HTTP/3, which is the transport layer that QUIC uses.
    • --with-stream_quic_module: Enables QUIC support for streaming.
    • --with-http_quic_module: Enables QUIC support for HTTP requests.
  2. Set Up Nginx Build Tools (CMake, Ninja): Use CMake and Ninja to compile Nginx. This is a more efficient build process.

    First, configure your build environment:

    bash
    mkdir ~/nginx-build cd ~/nginx-build cmake ../nginx \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/usr/local/nginx \ -DCMAKE_C_FLAGS="-g -O2" \ -DCMAKE_CXX_FLAGS="-g -O2" \ -DNGINX_QUIC=ON

    You may need to adjust paths based on your OpenSSL or BoringSSL installation.

  3. Compile Nginx:

    bash
    cmake --build . --parallel 4

    This command will compile Nginx with QUIC support. The --parallel 4 flag specifies that you want to use 4 CPU cores during the build process to speed it up.

  4. Install Nginx:

    After the build completes successfully, install Nginx:

    bash
    sudo cmake --install .

    This will install Nginx to /usr/local/nginx (or the path you specified).

6. Running Nginx with QUIC

After installing Nginx, you need to configure it to enable QUIC and HTTP/3.

  1. Update Nginx Configuration (nginx.conf): Modify your nginx.conf file to enable QUIC and HTTP/3 by adding the following directives:

    nginx
    server { listen 443 quic reuseport; listen [::]:443 quic reuseport; server_name example.com; ssl_certificate /path/to/cert.crt; ssl_certificate_key /path/to/cert.key; ssl_protocols TLSv1.3; ssl_prefer_server_ciphers off; http3 on; quic on; quic_recovery off; h3_max_concurrent_streams 100; # QUIC settings quic_recovery off; quic_max_idle_timeout 30s; quic_max_data_size 100M; # HTTP/3 and QUIC-specific headers add_header Alt-Svc 'h3-23=":443"'; # h3-23 means HTTP/3 add_header QUIC-Status $quic_status; }
  2. Start Nginx: Start Nginx normally using the following command:

    bash
    sudo /usr/local/nginx/sbin/nginx

    If everything is configured correctly, Nginx should now support QUIC and HTTP/3.


Conclusion

Building Nginx 1.27.0 with QUIC support on Windows is quite complex and not officially supported on Windows natively. However, using Windows Subsystem for Linux (WSL) is a practical solution. You can build Nginx with QUIC support using WSL on a Linux-like environment on Windows.

The key steps include:

  1. Setting up WSL.
  2. Installing dependencies like OpenSSL, Git, CMake, and Ninja.
  3. Cloning Nginx, the QUIC module, and OpenSSL.
  4. Configuring and compiling Nginx with the required QUIC and HTTP/3 modules.
  5. Configuring Nginx with the appropriate settings for QUIC and HTTP/3 support.

After the build, you can run and configure Nginx with QUIC support on your Windows machine using WSL.

posted @ 2024-11-15 11:52  锐洋智能  阅读(12)  评论(0编辑  收藏  举报