nginx如何启用对HTTP2的支持 | nginx如何验证HTTP2是否已启用
来源:互联网 发布:java volatile 原子类 编辑:程序博客网 时间:2024/05/19 00:41
nginx启用HTTP2特性
查看当前nginx的编译选项
1
#./nginx -V
2
3
nginx version: nginx/1.9.15
4
built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
5
built with OpenSSL 1.0.2g 1 Mar 2016
6
TLS SNI support enabled
7
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
启用http2支持
- 修改编译选项
在configure
的选项中加入--with-http_v2_module
,由于HTTP2需要SSL的支持,因此如缺少--with-http_ssl_module
选项,还需要加入--with-http_ssl_module
。 如下:./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
- 编译&升级
make & make install
- 修改配置文件,启用HTTP2,如下:
server { listen 8443 ssl http2 default_server; # 增加 http2 default_server server_name 192.168.0.107; ...}
- 验证配置文件
#./nginx -tnginx: the configuration file /home/jackie/software/nginx/conf/nginx.conf syntax is oknginx: configuration file /home/jackie/software/nginx/conf/nginx.conf test is successful
- 启动nginx
#./nginx
验证HTTP2是否已启用
方法一
使用高版本如56.0.2924.87的Chrome,按照如下步骤操作
- 使用Chrome访问启用http2的站点,比如Jackie的环境为https://192.168.0.107:8443。
- 新开TAB页,在地址栏中输入
chrome://net-internals/#http2
,检查HTTP/2 sessions
下的表格。 - 确认表格里是否出现了上一步访问的主机地址,比如192.168.0.107:8443。
方法二
使用curl命令,参考HTTP/2 with curl,执行如下命令,确认站点返回的协议是否为HTTP
curl --http2 -I 192.168.0.107:8443
如执行上述命令时遇到如下错误,说明系统当前安装的curl还不支持HTTP2协议。
curl https://192.168.0.107:8443/ --http2curl: (1) Unsupported protocol
可以执行如下命令,检查系统当前安装的curl支持的特性列表,确认是否包含HTTP2。
curl -Vcurl 7.47.0 (i686-pc-linux-gnu) libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.3Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftpFeatures: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets
从前述输出信息可以了解到,当前安装的curl还不支持HTTP2。
这时可参考如何启用curl命令HTTP2支持重新编译curl,加入HTTP2的支持。
方法三
安装Chrome插件HTTP/2 and SPDY indicator,安装完毕后访问启用HTTP2的站点,如果地址栏出现蓝色的闪电,说明站点已启用HTTP2。
不过Jackie身在墙内,安装总是失败,所以没有验证该方法的有效性。
完整的配置文件
如下是完整的配置文件,删除了一些与HTTP2特性不相关的内容。
01
worker_processes 1;
02
error_log
logs/error.log debug;
03
04
events {
05
worker_connections 1024;
06
}
07
08
http {
09
include
mime.types;
10
default_type application/octet-stream;
11
server_tokens off;
12
13
log_format main
'$remote_addr - $remote_user [$time_local] "$request" '
14
'$status $body_bytes_sent "$http_referer" '
15
'"$http_user_agent" "$http_x_forwarded_for"'
;
16
17
access_log logs/access.log main;
18
19
sendfile on;
20
tcp_nopush on;
21
22
keepalive_timeout 65;
23
charset utf-8;
24
25
server {
26
listen 8080;
27
server_name 192.168.0.107;
28
if
(
$scheme
~ http) {
29
return
https:
//$server_name:8443$request_uri;
30
}
31
}
32
33
server {
34
listen 8443 ssl http2 default_server;
35
server_name 192.168.0.107;
36
37
ssl_certificate /home/jackie/software/nginx_conf/server.crt;
38
ssl_certificate_key /home/jackie/software/nginx_conf/server.key;
39
40
ssl_session_cache shared:SSL:1m;
41
ssl_session_timeout 5m;
42
43
ssl_ciphers
'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA'
;
44
ssl_prefer_server_ciphers on;
45
46
add_header Strict-Transport-Security
"max-age=63072000; includeSubdomains; preload"
always;
47
add_header X-Frame-Options SAMEORIGIN always;
48
add_header X-XSS-Protection
"1; mode=block"
always;
49
add_header X-Content-Type-Options nosniff;
50
51
location ~ / {
52
index index.jsp;
53
proxy_pass http:
//127.0.0.1:18080;
54
proxy_set_header referer
''
;
55
include
proxy.conf;
56
}
57
58
#error_page 404 /404.html;
59
60
# redirect server error pages to the
static
page /50x.html
61
#
62
error_page 500 502 503 504 /50x.html;
63
location = /50x.html {
64
root html;
65
}
66
67
location ~ /\. {
68
deny all;
69
access_log off;
70
log_not_found off;
71
}
72
}
73
74
}
写在最后:FOR Freedom 看看外边的世界,以及IT这一行,少不了去Google查资料,最后,安利一个国外网络加速器。一枝红杏加速器,去Google查资料是绝对首选,连接速度快,使用也方便。我买的是99¥一年的,通过这个链接(http://my.yizhihongxing.com/aff.php?aff=2509)注册后输上会员中心得优惠码,平摊下来,每月才7块钱,特实惠。
本文标签: Nginx HTTP2 nginx启用HTTP2支持 nginx验证HTTP2 启用http2支持 服务器
转自 SUN'S BLOG - 专注互联网知识,分享互联网精神!
原文地址: 《nginx如何启用对HTTP2的支持 | nginx如何验证HTTP2是否已启用》
相关阅读:《我是 G 粉,一直关注 Google,最近 Google 有一些小动作,可能很多人不太了解》
相关阅读:《机器学习引领认知领域的技术创新,那么SaaS行业会被机器学习如何改变?》
相关阅读:《VPS 教程系列:Dnsmasq + DNSCrypt + SNI Proxy 顺畅访问 Google 配置教程》
相关阅读: 对程序员有用:2017最新能上Google的hosts文件下载及总结网友遇到的各种hosts问题解决方法及配置详解
相关阅读: 《win10永久激活教程以及如何查看windows系统是不是永久激活?》
相关BLOG:SUN’S BLOG - 专注互联网知识,分享互联网精神!去看看:www.whosmall.com
原文地址:http://whosmall.com/?post=238
- nginx如何启用对HTTP2的支持 | nginx如何验证HTTP2是否已启用
- nginx启用对HTTP2的支持
- 在nginx上启用http2,开启ssl,开启HSTS
- nginx 1.9 支持http2 协议
- 两年来的core折腾之路几点总结,附上nginx启用http2拿来即用的配置
- nginx http2配置
- nginx+http2+https
- Nginx 上配置 HTTP2
- nginx 配置http2.0
- nginx https http2
- nginx http2 源码分析
- Okhttp对http2的支持简单分析
- 启用Nginx目录浏览功能如何实现
- nginx配置http2无效不起作用
- Nginx上部署HTTPS + HTTP2
- http2概述及Java9对其的支持
- Ubuntu 配置 Nginx http2.0 支持 (二) 编译&配置Nginx 与 pagespeed
- 如何让Wireshark支持(加密的HTTP2等)HTTPS报文分析
- 欢迎使用CSDN-markdown编辑器
- JAVA 学习笔记
- 值得我们深入研究和学习:从零开始一步一步搭建坚不可摧的Web系统主流架构
- Jqgrid Toolbar
- 原生ECMAScript模块(ECMAScript modules)概述
- nginx如何启用对HTTP2的支持 | nginx如何验证HTTP2是否已启用
- 网站是PHP程序写的,我为什么说要选linux系统的php虚拟主机?
- 中文翻译为"具象状态传输"的RESTful的架构风格和设计思想
- 堆排序:什么是堆?什么是最大堆?二叉堆是什么?堆排序算法是怎么样的?PHP如何实现堆排序?
- 作为合格的 Android 开发者必须了解的Gradle文件及其背后的原理
- 关于 TensorFlow 的 gentlest 的介绍:了解 TensorFlow(TF)进行多个特征的线性回归和逻辑回归
- 如何从Chrome源码看浏览器如何计算CSS?
- 归纳9种CSS样式自动生成在线工具的优缺点
- 微信小程序开发笔记:为了做一个录制按钮,研究了下小程序的实时圆形进度条实现