This project contains a Dockerfile that builds a custom nginx Docker image with HTTP/3 support, along with a comprehensive test environment.
- Builds nginx version 1.26.1 (configurable via ENV variable)
- Includes HTTP/3 (QUIC) support
- Uses BoringSSL (Google's SSL library with native QUIC support)
- Includes common modules like SSL, HTTP/2, and streaming
- Optimized for a minimal, production-ready image
- Includes a test environment with:
- Go service for testing HTTP functionalities
- WebSocket support
- File upload/download capabilities
- Traffic analysis tools
.
├── Dockerfile # Main nginx image build configuration
├── README.md # This file
├── setup-ssl.sh # SSL certificate setup script
├── default.conf # Default nginx configuration
├── streaming/ # File streaming application
│ ├── backend/ # Go backend service
│ │ ├── main.go # Main application code
│ │ ├── go.mod # Go module definition
│ │ ├── go.sum # Go module checksums
│ │ ├── Dockerfile # Backend Docker configuration
│ │ └── data/ # Data directory for files
│ ├── frontend/ # Frontend static files
│ │ ├── index.html # Main HTML file
│ │ ├── css/ # CSS styles
│ │ └── js/ # JavaScript code
│ ├── nginx.conf # Default Nginx configuration
│ ├── nginx.conf.local # Local development Nginx config
│ ├── nginx.conf.production # Production Nginx config
│ ├── default.conf # Default server configuration
│ ├── default.conf.local # Local server configuration
│ ├── default.conf.production # Production server config
│ ├── default.conf.production.template # Template for production
│ ├── docker-compose.yml # Base Docker Compose config
│ ├── docker-compose.local.yml # Local environment overrides
│ └── docker-compose.production.yml # Production overrides
├── test/ # Test environment
│ ├── README.md # Test environment documentation
│ ├── docker-compose.yml # Test services configuration
│ ├── docker-compose.local.yml # Local test overrides
│ ├── server.conf.local # Local test server config
│ ├── hello-service/ # Go test service
│ │ ├── main.go # Test service code
│ │ └── Dockerfile # Test service build
│ └── nginx/ # Nginx test configuration
│ ├── nginx.conf # Test nginx configuration
│ └── conf.d/ # Test server configurations
└── certs/ # SSL certificates directory
└── live/ # Let's Encrypt certificates
└── example.com/ # Domain-specific certs
├── fullchain.pem # Full certificate chain
├── privkey.pem # Private key
└── chain.pem # Certificate chain
- Docker
- Docker Compose V2 (for test environment)
- SSL certificates (for HTTPS/HTTP3 testing)
The project includes a setup-ssl.sh script that automates SSL certificate generation using Let's Encrypt. The script handles:
- Certificate generation for both domain.com and www.domain.com
- Proper certificate placement for nginx
- Automatic renewal setup
- Container restart with new certificates
# Basic usage with just domain
./setup-ssl.sh -d example.com
# With custom email
./setup-ssl.sh -d example.com -e admin@example.com
# With custom container and image names
./setup-ssl.sh -d example.com -c my-nginx -i my-http3-imageAvailable options:
-d domain: Domain name (required, e.g., example.com)-e email: Email for Let's Encrypt notifications (default: admin@domain)-c name: Container name (default: nginx-https-server)-i name: Image name (default: nginx-http3)-h: Show help message
The script will:
- Stop any existing nginx container
- Generate certificates using Let's Encrypt
- Create proper symbolic links
- Start nginx with the new certificates
- Set up monthly automatic renewal
After running the script, certificates will be available at:
certs/live/your-domain.com/
├── fullchain.pem # Full certificate chain
├── privkey.pem # Private key
└── chain.pem # Certificate chain
docker build -t nginx-http3 .docker run -d \
--name nginx-http3-server \
-p 80:80 \
-p 443:443 \
-p 443:443/udp \
-v /path/to/nginx.conf:/etc/nginx/nginx.conf:ro \
-v /path/to/conf.d:/etc/nginx/conf.d:ro \
-v /path/to/certs:/etc/nginx/certs:ro \
nginx-http3# Check container status
docker ps
# Check nginx version and configuration
docker exec nginx-http3-server nginx -v
docker exec nginx-http3-server nginx -tThe project includes a comprehensive test environment located in the test/ directory. To use it:
-
Navigate to the test directory:
cd test
-
Start the test environment:
docker compose up --build
-
Access the test services:
- HTTP: http://localhost
- HTTPS/HTTP3: https://localhost
- WebSocket test page: http://localhost/ws-test
For detailed information about the test environment, including available endpoints and traffic analysis, see test/README.md.
To enable HTTP/3 support in nginx, you need to properly configure your server blocks. HTTP/3 requires HTTPS and QUIC protocol support. Here's the correct configuration:
server {
# Standard HTTP port - redirect to HTTPS
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}
server {
# Configure HTTP/3
listen 443 ssl; # Standard HTTPS
http2 on; # Enable http2
listen 443 quic reuseport; # UDP port for QUIC+HTTP/3
server_name example.com;
# SSL certificates
ssl_certificate /etc/nginx/certs/live/example.com/fullchain.pem;
ssl_certificate_key /etc/nginx/certs/live/example.com/privkey.pem;
# Add Alt-Svc header to inform clients about HTTP/3 support
add_header Alt-Svc 'h3=":443"; ma=86400';
# SSL settings
ssl_protocols TLSv1.3; # TLSv1.3 preferred for HTTP/3
# Your server configuration
location / {
root /usr/share/nginx/html;
index index.html;
}
}Key points to understand:
-
Dual Listening:
- Standard TLS over TCP:
listen 443 ssl; - Enable HTTP/2:
http2 on;
- Standard TLS over TCP:
-
HTTP/3 Enabling:
- QUIC+HTTP/3 over UDP:
listen 443 quic reuseport;
- QUIC+HTTP/3 over UDP:
-
Alt-Svc Header:
- The
Alt-Svcheader tells clients the server supports HTTP/3 - The value
h3=":443"; ma=86400means HTTP/3 is available on port 443 with a max age of 1 day
- The
-
TLSv1.3 Recommendation:
- HTTP/3 works best with TLSv1.3 for optimal performance
You can modify the Dockerfile to:
- Change the nginx version by updating the
NGINX_VERSIONenvironment variable - Add or remove compile options in the
./configurestep - Include additional dependencies or modules
- Modify build optimization flags
To verify HTTP/3 support:
-
Use curl with HTTP/3 support:
curl --http3 https://localhost/api/
-
Check the Alt-Svc header in responses:
curl -I https://localhost/api/
-
Use Chrome or Edge browser to test HTTP/3 connections (they support HTTP/3 by default)
The nginx source code is subject to the BSD-like license used by the nginx project.