📜 ⬆️ ⬇️

A test version of the HTTP / 2 module for NGINX has been published.

Introduced alpha version of the patch that provides HTTP / 2 support for NGINX. NGINX version 1.9.0 or later is required for this patch. Full HTTP / 2 support for commercial and non-commercial versions of NGINX is planned for the end of this year. Reviews can be sent to the newsletter nginx-devel .

Since the patch is an alpha version, it is not recommended to use it in work projects. If you want to use the features of HTTP / 2 for work sites, you should pay attention to NGINX version 1.5.10 and newer, which fully support the SPDY / 3.1 protocol . As the predecessor of HTTP / 2, SPDY has the same advantages as HTTP / 2, but at the same time has wider support among current browser versions.

About HTTP / 2 support in NGINX


HTTP / 2 is a new protocol, so there are some concerns and misunderstandings associated with it. One of the main concerns is that the implementation of HTTP / 2 support requires a change in the architecture of the entire application. This fear and many others related to HTTP / 2 are groundless. In fact, for applications using NGINX, HTTP / 2 support is implemented using minor architecture changes.

To facilitate the transition to the new protocol, NGINX acts as an “HTTP / 2 gateway”. On the client side, NGINX communicates with browsers via HTTP / 2 (if HTTP / 2 support is implemented for the browser), and on the server side via HTTP / 1.x (or FastCGI, uwsgi, SCGI) as before. In between the client and the backend, NGINX converts HTTP / 2 to HTTP / 1.x (or FastCGI, etc.). In other words, servers and applications proxied through NGINX do not require changes to switch to HTTP / 2. The only necessary modification of existing HTTPS configurations will be the addition of the http2 parameter to the listen directives (the ssl parameter is also required):
')
listen 443 ssl http2 default_server; 

As of June 2015, more than 50% of users use browsers with HTTP / 2 support. In other words, the implementation of HTTP / 2 browsers is quite high and will increase over time. For simultaneous operation of HTTP / 1.x and HTTP / 2 in NGINX, Application Layer Protocol Negotiation ( ALPN ) is used, which is an extension of TLS. When the browser is connected to the server, a list of supported protocols is sent. If h2 is on the list, then NGINX uses HTTP / 2 for the connection. If ALPN support is not implemented in the browser or there is no h2 in the list of supported protocols, then NGINX will use HTTP / 1.x.

As you might have guessed, some of the optimizations for HTTP / 1.x are now anti-pattern for HTTP / 2 . Optimizations such as using sprites, combining or inlining images, and sharing resources between domains that helped with HTTP / 1.x are no longer needed with HTTP / 2. You can, of course, implement HTTP / 2 using these optimizations, but we strongly recommend getting rid of them to increase performance.

Building NGINX with HTTP / 2


  1. Install OpenSSL version 1.0.2 or later , required to support ALPN.
  2. Download and unpack NGINX version 1.9.0 or later:
     $ wget http://nginx.org/download/nginx-1.9.3.tar.gz $ tar zxvf nginx-1.9.3.tar.gz $ cd nginx-1.9.3 

  3. Download the patch:
     $ wget http://nginx.org/patches/http2/patch.http2.txt 

  4. Check the possibility of applying the patch:
     $ patch -p1 --dry-run < patch.http2.txt 

  5. If there are no errors, we use:
     $ patch -p1 < patch.http2.txt 

  6. Configure NGINX with the necessary options:
    • to build NGINX with OpenSSL from source and static linking:
       $ ./configure --with-http_ssl_module \ --with-http_v2_module \ --with-debug \ --with-openssl=/path/to/openssl-1.0.2 \ ... 
    • If OpenSSL is installed as a third-party library (for example, on Mac OS X):
       $ ./configure --with-http_ssl_module \ --with-http_v2_module \ --with-debug \ --with-cc-opt="-I/opt/local/include" \ --with-ld-opt="-L/opt/local/lib" \ ... 

  7. After that we collect NGINX:
     $ make 

NGINX Setup


To enable HTTP / 2 support, add the ssl and http2 parameters to the listen directives:
 server { listen 443 ssl http2 default_server; ssl_certificate server.crt; ssl_certificate_key server.key; ... } 

Note: the ssl parameter is required. At the time of this writing, browsers do not support HTTP / 2 without SSL encryption.

There are some good plugins for Google Chrome and Firefox to test HTTP / 2.

Remarks


As with earlier releases, there are a number of problems:


Special thanks


NGINX, Inc. Thanks to Dropbox and Automattic companies that are active users of NGINX and participate in the development sponsorship. Their contribution has accelerated the creation of the HTTP / 2 module and we hope that you, in turn, will be able to support them.

UPD: HTTP2 support has already been added to the open-source version of NGINX. Anyone can download the source .

Source: https://habr.com/ru/post/264361/


All Articles