How do I enable HTTP/2 in Nginx?
Change listen 443 ssl to listen 443 ssl http2 in the server block. HTTP/2 allows multiplexing (multiple requests over one connection), header compression, and is faster than HTTP/1.1. It requires SSL (HTTPS). Test with curl -I --http2 https://yourdomain.com.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Nginx Performance Updates and Optimization Gzip, Caching, and Worker Tuning
Enable gzip compression (level 6, text types), cache static files for 1 year with immutable, use proxy_buffering to free Node.js, enable keep-alive connections (65s timeout, 32 upstream), use HTTP/2, set worker_processes auto with 2048 connections, and disable access logging for static files.
Brotli is a compression algorithm that's ~15-20% better than gzip for text content. Install libnginx-mod-http-brotli-filter, enable with brotli on and brotli_comp_level 6. Use it alongside or instead of gzip for better compression.
Add a location block matching static file extensions (js, css, png, jpg, etc.) with expires 1y, add_header Cache-Control 'public, immutable', and access_log off. React build files have hashed names so aggressive caching is safe new versions get new URLs.
Still have questions?
Browse all our FAQs or reach out to our support team
