{"id":8138,"date":"2018-12-21T13:28:27","date_gmt":"2018-12-21T10:28:27","guid":{"rendered":"https:\/\/www.howtoforge.com\/how-to-enable-http-2-in-nginx\/"},"modified":"2018-12-21T13:28:27","modified_gmt":"2018-12-21T10:28:27","slug":"%d8%a2%d9%85%d9%88%d8%b2%d8%b4-%d9%81%d8%b9%d8%a7%d9%84-%d8%b3%d8%a7%d8%b2%db%8c-http-2-%d8%af%d8%b1-nginx","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/%d8%a2%d9%85%d9%88%d8%b2%d8%b4-%d9%81%d8%b9%d8%a7%d9%84-%d8%b3%d8%a7%d8%b2%db%8c-http-2-%d8%af%d8%b1-nginx\/","title":{"rendered":"\u0622\u0645\u0648\u0632\u0634 \u0641\u0639\u0627\u0644 \u0633\u0627\u0632\u06cc HTTP\/2 \u062f\u0631 NGINX"},"content":{"rendered":"<article>\n<p dir=\"ltr\" style=\"text-align: left;\">Hypertext Transfer Protocol Version 2 (<strong>HTTP\/2<\/strong>) is the\u00a0latest version of the HTTP protocol,\u00a0published as an IETF standard in\u00a0RFC\u00a07540\u00a0in\u00a02015.\u00a0The focus of the protocol is on performance; specifically, end-user perceived latency, network and server resource usage. One major goal is to allow the use of a single connection from browsers to a Web site. The protocol is backward compatible, so\u00a0HTTP methods, status codes and semantics are the same as for previous versions of the protocol. Nginx has HTTP\/2 support since version 1.9.5.\u00a0\u00a0In this tutorial,\u00a0I&#8217;m going to assume that you already have a working TLS configuration, and that you have\u00a0required Nginx version installed on your Linux distribution of choice, and that you know how to use Let&#8217;s Encrypt, or you know how to issue a self-signed certificate.\u00a0<\/p>\n<h2 id=\"requirements\" dir=\"ltr\" style=\"text-align: left;\">\u0646\u06cc\u0627\u0632\u0645\u0646\u062f\u06cc \u0647\u0627<\/h2>\n<p dir=\"ltr\" style=\"text-align: left;\">To enable\u00a0HTTP\/2 in Nginx you will need to fulfill the following requirements:<\/p>\n<ul dir=\"ltr\" style=\"text-align: left;\">\n<li>Nginx version 1.9.5 or greater. You can check your Nginx version by running\u00a0(<code>nginx -v<\/code>) command.<\/li>\n<li>OpenSSL version 1.0.2 or greater. You can check your OpenSSL version by running\u00a0(OpenSSL version) command.<\/li>\n<li>SSL\/TLS certificate from Let&#8217;s Encrypt or a self-signed certificate.<\/li>\n<li>TLS 1.2 or higher protocol enabled. Otherwise, you will not be able to use HTTP\/2. Implementations of HTTP\/2 must use TLS version 1.2 or higher for HTTP\/2 over TLS.<\/li>\n<\/ul>\n<h2 id=\"enable-http-in-nginx\" dir=\"ltr\" style=\"text-align: left;\">\u0641\u0639\u0627\u0644 \u0633\u0627\u0632\u06cc<\/h2>\n<p dir=\"ltr\" style=\"text-align: left;\">To enable\u00a0HTTP\/2 in Nginx, we\u00a0have to\u00a0add the\u00a0<code>http2<\/code>\u00a0parameter to the\u00a0<code>listen<\/code>\u00a0directive in\u00a0our virtual host:<\/p>\n<pre dir=\"ltr\"><code spellcheck=\"false\">listen 443 ssl http2;<\/code><\/pre>\n<p dir=\"ltr\" style=\"text-align: left;\">And reload your Nginx configuration:<\/p>\n<pre class=\"command\" dir=\"ltr\"><code spellcheck=\"false\">sudo systemctl reload nginx.service<\/code><\/pre>\n<p dir=\"ltr\" style=\"text-align: left;\">Here is the minimal virtual server configuration that can be used to enable HTTP\/2 in some virtual host:<\/p>\n<pre dir=\"ltr\"><code spellcheck=\"false\"><code spellcheck=\"false\">server {<\/code><\/code><\/pre>\n<p dir=\"ltr\" style=\"text-align: left;\">listen 443 ssl <strong>http2<\/strong>;<br \/>listen [::]:443 ssl <strong>http2<\/strong>;<\/p>\n<pre dir=\"ltr\"><code spellcheck=\"false\"><code spellcheck=\"false\"><\/code><\/code><\/pre>\n<p dir=\"ltr\" style=\"text-align: left;\">server_name example.com;<br \/>root \/path\/to\/public;<\/p>\n<pre dir=\"ltr\"><code spellcheck=\"false\"><code spellcheck=\"false\"><\/code><\/code><\/pre>\n<p dir=\"ltr\" style=\"text-align: left;\">ssl_certificate \/path\/to\/certificate.crt;<br \/>ssl_certificate_key \/path\/to\/private.key;<\/p>\n<pre dir=\"ltr\"><code spellcheck=\"false\"><code spellcheck=\"false\"><\/code><\/code><\/pre>\n<p dir=\"ltr\" style=\"text-align: left;\">ssl_protocols <strong>TLSv1.2<\/strong>;<\/p>\n<pre dir=\"ltr\"><code spellcheck=\"false\"><code spellcheck=\"false\"><\/code><\/code><\/pre>\n<p dir=\"ltr\" style=\"text-align: left;\">}<\/p>\n<pre dir=\"ltr\"><code spellcheck=\"false\"><code spellcheck=\"false\"><\/code><\/code><\/pre>\n<p dir=\"ltr\" style=\"text-align: left;\">To\u00a0check if your server supports HTTP\/2, you can use your browser dev tools or Nginx log files. The below\u00a0is\u00a0a screenshot from Google Chrome browser that shows\u00a0HTTP\/2\u00a0in action on https:\/\/example.com\u00a0domain.<\/p>\n<p dir=\"ltr\" style=\"text-align: left;\"><a id=\"img-h2\" class=\"fancybox\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_enable_http_2_in_nginx\/big\/h2.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/12\/how-to-enable-http-2-in-nginx.png\" alt=\"\" title=\"\"><\/a><\/p>\n<p dir=\"ltr\" style=\"text-align: left;\">You can also use Nginx\u00a0$http2 embedded variable to see\u00a0negotiated protocol. This variable will log:\u00a0\u201c<code>h2<\/code>\u201d for HTTP\/2 over TLS, \u201c<code>h2c<\/code>\u201d for HTTP\/2 over cleartext TCP, or an empty string otherwise in the Nginx access log if configured to do so.<\/p>\n<\/article>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hypertext Transfer Protocol Version 2 (HTTP\/2) is the\u00a0latest version of the HTTP protocol,\u00a0published as an IETF standard in\u00a0RFC\u00a07540\u00a0in\u00a02015.\u00a0The focus of the protocol is on performance; specifically, end-user perceived latency, network and server resource usage. One major goal is to allow the use of a single connection from browsers to a Web site. The protocol is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-8138","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/8138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=8138"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/8138\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=8138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=8138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=8138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}