Enable HTTP/2 on Nginx
On Nginx 1.25.1 or newer, turn HTTP/2 on with http2 on; inside the TLS server block, then run nginx -t and reload. Browsers use HTTP/2 only over HTTPS with ALPN. Older Nginx still uses listen 443 ssl http2;. Confirm the response line says HTTP/2.
A root-level walkthrough of the Nginx HTTP/2 switch for VPS owners: module check, the two syntaxes by version, verification, and what not to tune.
knowledge
- Read time
- 4 min
- Sections
- 5
- Updated
- 14 Nov 2026
- Written by
- WebJi® team
Last editorial update: 15 November 2026.
What HTTP/2 changes on Nginx
HTTP/2 carries many streams on one connection and compresses headers with HPACK, where HTTP/1.1 usually queues requests on each connection so a page full of files waits its turn. Multiplexing is the change. It is not a faster disk and not a new bandwidth cap.
Nginx cuts the response into chunks; the default http2_chunk_size is 8k. A much smaller chunk adds overhead, and a much larger chunk weakens prioritization because of head-of-line blocking inside the stream — leave 8k unless you have measured a reason to move it. One large file still moves at the speed of the link: the protocol helps when the browser asks for CSS, JavaScript and images together. If the wait is PHP or the database, start with why a website is slow. The edit itself needs root, which VPS hosting includes and shared hosting does not.
Prerequisites before you enable HTTP/2 on Nginx
Three checks come before the directive: the module in the build, the version, and TLS with ALPN. ngx_http_v2_module arrived in Nginx 1.9.5 and is not in the binary unless the build used --with-http_v2_module. Run nginx -V and look for that flag; nginx -v prints the version, and the version picks the syntax below.
- Module flag:
--with-http_v2_modulein thenginx -Voutput. - Version:
nginx -v, because 1.25.1 changes the syntax. - TLS: a certificate on port 443, and OpenSSL 1.0.2 or newer for ALPN.
- Ciphers: off the RFC 9113 Appendix A blacklist when
ssl_prefer_server_ciphersis on.
Browsers negotiate HTTP/2 only on HTTPS. If the padlock is missing, install an SSL certificate first, then come back to this server block. Cleartext HTTP/2 is h2c — the embedded variable $http2 reads h2 on TLS, h2c on cleartext TCP, or empty — but Chrome and Firefox will not use h2c, so a port 80 listener does not switch those browsers. A blacklisted cipher suite fails the handshake while nginx -t still passes, so keep TLS at 1.2 or newer and delete any spdy token still on a listen line; SPDY support was withdrawn, and leaving spdy beside http2 is a bad listen line, not a fallback.
Enable HTTP/2 in the Nginx server block
On Nginx 1.25.1 and newer the switch is the http2 directive: it appeared in that version, defaults to off, and is valid in the http and server contexts. The module page's example is listen 443 ssl; followed by http2 on; plus the certificate lines.
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
Put those lines in the server block that already has the certificate. Omit the IPv6 listen line if this host has no IPv6 listener, and leave the existing ssl_certificate and ssl_certificate_key lines where they are.
| Nginx | What turns HTTP/2 on | Where it sits |
|---|---|---|
| Before 1.25.1 | listen 443 ssl http2; | On the listen line |
| 1.25.1 and newer | http2 on; | Server block, next to listen 443 ssl;. Default is off |
Before 1.25.1, published steps put the flag on the listen line, and older guides — a June 2022 community thread and an SSL vendor's steps among them — still show that form. Use the form that matches nginx -v, and read the warning from nginx -t instead of stacking both forms. A proxy in front can also speak HTTP/1.1 to your origin while the browser uses HTTP/2 to the proxy, so confirm the hop you actually control.
- Copy the file you will edit. On a VPS it is often under
/etc/nginx/sites-available/or/etc/nginx/conf.d/, not always the main nginx.conf. - Add the version-correct lines in the server block that already holds the certificate, mirroring them on the IPv6 listen line when that line exists.
- Run
nginx -t. Fix the path it names; a failed test leaves the running config untouched. - Reload with
systemctl reload nginx. A reload is enough — a full restart is not required for this change. - If nginx -t names a file you cannot place, email support@webji.services; the mailbox is 24/7 in Hindi and English, and the office phone is not a support line.
Verify HTTP/2 with DevTools and curl
The proof is the protocol on the response, not the padlock: curl -sI --http2 https://example.com should show HTTP/2 on the status line. If that curl binary was built without HTTP/2, the error is the client — run the same command from a machine whose curl supports it.
In Chrome or Firefox, open DevTools, choose Network, turn on the Protocol column and reload. h2 means the browser negotiated HTTP/2; HTTP/1.1 means it did not — no certificate, no ALPN, the directive on the wrong server, or a proxy that still speaks HTTP/1.1. On the server, $http2 is h2 when that request is HTTP/2 over TLS, and empty when it is not.
HTTP/2 server push and stream limits on Nginx
Do not enable server push as part of turning HTTP/2 on: http2_push, http2_push_preload and http2_max_concurrent_pushes have been obsolete since Nginx 1.25.1, and the module page names early_hints as the replacement for push. What was worth tuning instead moved to core directives in 1.19.7.
keepalive_timeoutreplaceshttp2_idle_timeout.keepalive_requestsreplaceshttp2_max_requests.large_client_header_buffersreplaceshttp2_max_field_sizeandhttp2_max_header_size.client_header_timeoutreplaceshttp2_recv_timeout.
Frequently asked questions
How do I enable HTTP/2 in Nginx?
On Nginx 1.25.1 or newer, put http2 on; in the TLS server block, run nginx -t, and reload. On older Nginx, use listen 443 ssl http2;. nginx -V must show --with-http_v2_module.
Does HTTP/2 require HTTPS?
Browsers negotiate HTTP/2 only over TLS with ALPN, which needs OpenSSL 1.0.2 or newer. Cleartext h2c exists, but Chrome and Firefox will not use it. Keep the certificate on port 443.
Why does the HTTP/2 handshake fail on Nginx?
A cipher on the RFC 9113 Appendix A blacklist, with ssl_prefer_server_ciphers on, fails the handshake. A leftover spdy flag on listen does the same kind of damage, and a directive on a server block with no certificate never negotiates. nginx -t can still pass through all three.
Does http2 on enable HTTP/3?
No. HTTP/3 is a separate protocol over QUIC, and the http2 on; directive does not turn it on. Set HTTP/2 first, and treat HTTP/3 as its own change after you know the build supports it.
Can I enable HTTP/2 on shared hosting?
Not by editing Nginx yourself — the directive needs root on the server, which shared plans do not give you. On managed platforms the host controls it; if you need to touch the server block, that is a VPS job.
Last editorial update: 15 November 2026. Syntax and version facts checked against the nginx module documentation.
Ready to get started with WebJi®?
Join 12,000+ businesses across India and overseas. INR pricing, 18% GST shown before payment and 24/7 email support in Hindi and English — average first reply under 60 minutes.