Chapter 8. HTTP/2
8.0 Introduction
HTTP/2 is a major revision to the HTTP protocol. Much of the work done in this version was focused on the transport layer, such as enabling full request and response multiplexing over a single TCP connection. Efficiencies were gained through the use of compression on HTTP header fields, and support for request prioritization was added. Another large addition to the protocol was the ability for the server to push messages to the client. This chapter details the basic configuration for enabling HTTP/2 in NGINX as well as configuring Google’s open source remote procedure call (gRPC) and HTTP/2 server push support.
8.1 Basic Configuration
Problem
You want to take advantage of HTTP/2.
Solution
Turn on HTTP/2 on your NGINX server:
server { listen 443 ssl http2 default_server; ssl_certificate server.crt; ssl_certificate_key server.key; # ... }
Discussion
To turn on HTTP/2, you simply need to add the http2
parameter to the listen
directive. The catch, however, is that although the protocol does not require the connection to be wrapped in SSL/TLS, some implementations of HTTP/2 clients support only HTTP/2 over an encrypted connection. Another caveat is that the HTTP/2 specification has blocked a number of TLS 1.2 cipher suites, and therefore will fail the handshake. The ciphers NGINX uses by default are not on the blocklist. The Application-Layer Protocol Negotiation of TLS allows the application layer to negotiate which protocol should be used ...
Get NGINX Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.