Skip to Content
NGINX Cookbook, 2nd Edition
book

NGINX Cookbook, 2nd Edition

by Derek DeJonghe
May 2022
Intermediate to advanced
202 pages
4h 17m
English
O'Reilly Media, Inc.
Content preview from NGINX Cookbook, 2nd Edition

Chapter 8. HTTP/2

8.0 Introduction

HTTP/2 is a major revision to the HTTP protocol. Much of the change to this revision is 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 only support 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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

NGINX Cookbook

NGINX Cookbook

Tim Butler
NGINX Cookbook

NGINX Cookbook

Derek DeJonghe
NGINX Cookbook

NGINX Cookbook

Derek DeJonghe
Nginx HTTP Server - Fourth Edition

Nginx HTTP Server - Fourth Edition

Martin Bjerretoft Fjordvald, Nedelcu

Publisher Resources

ISBN: 9781098126230Errata Page