nginx enable HTTP2 feature
View the current Nginx compilation options
#./nginx-v
nginx version:nginx/1.9.15
built by GCC 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
built With OpenSSL 1.0.2g 1 April
TLS SNI support enabled
configure arguments:--prefix=/home/jackie/software/ Nginx--with-openssl=/home/jackie/downloads/nginx/openssl-1.0.2g--with-pcre=/home/jackie/downloads/nginx/ pcre-8.38--with-zlib=/home/jackie/downloads/nginx/zlib-1.2.8--with-http_ssl_module--with-threads--with-debug
Enable HTTP2 supportThe Modify compilation option adds--with-http_v2_module to the Configure option, because HTTP2 requires SSL support, so if the--with-http_ssl_module option is missing, you need to add--with-http_ssl _module. As follows:
./configure--prefix=/home/jackie/software/nginx \
--with-openssl=/home/jackie/downloads/nginx/ openssl-1.0.2g \
--with-pcre=/home/jackie/downloads/nginx/pcre-8.38 \
--with-zlib=/home/jackie/downloads /nginx/zlib-1.2.8 \
--with-http_ssl_module \
--with-threads \
--with-debug \
--with-http_v2_module
Compiling & Upgrading
Make & make Install
Modify the configuration file to enable HTTP2, as follows:
server {
Listen 8443 SSL HTTP2 default_server; # add HTTP2 default_server
server_name 192.168.0.107;
...
}
Verifying the configuration file
#./nginx-t
nginx:the Configuration file/home/jackie/software/nginx/conf/nginx.conf syntax is OK
nginx: Configuration file/home/jackie/software/nginx/conf/nginx.conf test is successful
Start Nginx
#./nginx
Verify that HTTP2 is enabled
Method OneUsing Chrome with a high version like 56.0.2924.87, follow these steps to access HTTP2-enabled sites using chrome, such as Jackie's environment for https://192.168.0.107:8443. New tab page, enter chrome://net-internals/#http2 in the Address bar, check the table under HTTP/2 sessions. Verify that the host address of the previous step is present in the form, such as 192.168.0.107:8443.
Method TwoUsing the Curl command, refer to HTTP/2 with Curl and execute the following command to confirm whether the protocol returned by the site is HTTP
Curl--http2-i 192.168.0.107:8443
If you encounter the following error when executing the above command, the system currently installed curl does not support the HTTP2 protocol.
Curl https://192.168.0.107:8443/--HTTP2
Curl: (1) Unsupported protocol
You can verify that the HTTP2 is included by checking the list of features that are currently installed by the system for curl support by executing the following command.
Curl-v
Curl 7.47.0 (I686-PC-LINUX-GNU) libcurl/7.47.0 gnutls/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.3
Protocols:dict file ftp FTPs Gopher HTTP HTTPS IMAP imaps LDAP ldaps POP3 pop3s rtmp rtsp SMB SMBs SMTP Smtps telnet tftp
features:asynchdns IDN IPv6 largefile gss-api Kerberos SPNEGO NTLM ntlm_wb SSL libz tls-srp unixsockets
From the above output information can be learned that the current installation of Curl does not support HTTP2. You can refer to how to enable the Curl command HTTP2 support for recompiling Curl, adding HTTP2 support.
Method ThreeInstall the chrome plugin HTTP/2 and SPDY indicator, after installation, access the HTTP2-enabled site, if the address bar appears Blue Lightning, the site is enabled HTTP2. But the Jackie is in the wall, the installation always fails, so the validity of the method is not verified.
Complete configuration fileThe following is the complete configuration file, which removes some content that is not related to the HTTP2 feature.
Worker_processes 1;
Error_log Logs/error.log Debug;
Events {worker_connections 1024;}
HTTP {include mime.types;
Default_type Application/octet-stream;
Server_tokens off; Log_format Main ' $remote _addr-$remote _user [$time _local] "$request" ' $status $body _bytes_sent
"$http _referer" "$http _user_agent" "$http _x_forwarded_for";
Access_log Logs/access.log Main;
Sendfile on;
Tcp_nopush on;
Keepalive_timeout 65;
CharSet Utf-8;
server {listen 8080;
server_name 192.168.0.107;
if ($scheme ~ http) {return https://$server _name:8443$request_uri;
}} server {Listen 8443 SSL http2 default_server;
server_name 192.168.0.107;
SSL_CERTIFICATE/HOME/JACKIE/SOFTWARE/NGINX_CONF/SERVER.CRT;
Ssl_certificate_key/home/jackie/software/nginx_conf/server.key; Ssl_session_cacHe shared:ssl:1m;
Ssl_session_timeout 5m; Ssl_ciphers ' Ecdhe-rsa-aes256-gcm-sha384:ecdhe-rsa-aes128-gcm-sha256:dhe-rsa-aes256-gcm-sha384:d
He-rsa-aes128-gcm-sha ';
Ssl_prefer_server_ciphers on; Add_header strict-transport-security "max-age=63072000; Includesubdomains;
Preload "always;
Add_header x-frame-options Sameorigin always; Add_header x-xss-protection "1;
Mode=block "always;
Add_header x-content-type-options Nosniff;
Location ~/{index index.jsp;
Proxy_pass http://127.0.0.1:18080;
Proxy_set_header Referer ';
Include proxy.conf;
} #error_page 404/404.html;
# REDIRECT Server error pages to the static page/50x.html # Error_page 502 503 504/50x.html;
Location =/50x.html {root html; } location ~/\.
{Deny All; access_lOG off;
Log_not_found off;
}
}
}
References
nginx-enabled HTTP2 dataModule ngx_http_v2_module nginx http2.0 performance is too counter-day, HTTPS website performance optimization upgrade Nginx to 1.9.12 and open HTTP/2 HAProxy, nginx configuration HTTP/2 Complete Guide Nginx HTTP2 compiler front-end engineer to learn Nginx primer front-end engineer Learning Nginx Practice Configuration HTTP2.0 Solution Nginx configuration HTTP2 not take effect, Google Chrome still use http1.1 protocol problem may be Nginx configuration HTTP2 the most practical tutorial
More information about HTTP2Http,http2.0,spdy,https you should know something. Another way to optimize front-end Performance--http2.0 HTTP 2.0 Details HTTP2.0 protocol front-end engineers should know what the HTTP level is. from which ways to know better. Front end should be aware of those things HTTP2 HTTP 2.0 Why Domain sharding are bad News for Mobile performance and Users HTTP2 explained HTTP2 explained
otherDNS workflow and principles the relationship between domain name, IP and DNS DNS workflow and principle domain name, the relationship between IP and DNS browser loading and rendering HTML in the order of JAVASCRIPT loading and executing from the input URL to the page loading completed the process of what happened. Introduction to the browser's rendering principle CSS performance from the browser rendering principle
View Original: http://www.jackieathome.net/archives/437.html