1.http2协议

  • HTTP 2.0 的主要目标是改进传输性能,实现低延迟和高吞吐量。从另一方面看,HTTP 的高层协议语义并不会因为这次版本升级而受影响。所有HTTP 首部、值,以及它们的使用场景都不会变。
  • 现有的任何网站和应用,无需做任何修改都可以在HTTP 2.0 上跑起来。不用为了利用HTTP 2.0 的好处而修改标记。HTTP 服务器必须运行HTTP 2.0 协议,但大部分用户都不会因此而受到影响
  • centos6安装参考:
  • https://imhanjm.com/2017/04/20/nginx%20http2%E7%BC%96%E8%AF%91%E5%AE%89%E8%A3%85/
  • http://blog.csdn.net/littlesmallless/article/details/59173287

2.编译安装nginx

#1.安装依赖
[root@hadoop_node1 ~]# yum install -y gcc gcc-c++ pcre pcre-devel openssl-devel zlib zlib-devel
#2.下载安装
[root@hadoop_node1 ~]# cd /usr/local/src/
[root@hadoop_node1 src]# wget http://nginx.org/download/nginx-1.10.3.tar.gz
[root@hadoop_node1 src]# tar xf nginx-1.10.3.tar.gz
[root@hadoop_node1 src]# cd nginx-1.10.3/
#3.编译参数
[root@hadoop_node1 nginx-1.10.3]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx-1.10.3 --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module
[root@hadoop_node1 nginx-1.10.3]# make && make install
  • --with-http_v2_module 支持http2协议
[root@hadoop_master nginx]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.10.3
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --user=nginx --group=nginx --prefix=/usr/local/nginx-1.10.3 --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module

3.生成证书

  • 因为没有真的证书,所以生成一个伪证书
[root@hadoop_node1 nginx-1.10.3]# ln -s /usr/local/nginx-1.10.3/ /usr/local/nginx
[root@hadoop_node1 nginx-1.10.3]# cd /usr/local/nginx/conf/
[root@hadoop_node1 conf]# mkdir key
[root@hadoop_node1 conf]# cd key/
#自定义密码
[root@hadoop_node1 key]# openssl genrsa -des3 -out server.key 1024
Generating RSA private key, 1024 bit long modulus
..........++++++
..........++++++
e is 65537 (0x10001)
Enter pass phrase for server.key:
Verifying - Enter pass phrase for server.key:
#签发证书
[root@hadoop_node1 key]# openssl req -new -key server.key -out server.csr
Enter pass phrase for server.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:BJ
Locality Name (eg, city) [Default City]:BJ
Organization Name (eg, company) [Default Company Ltd]:SDU
Organizational Unit Name (eg, section) []:SA
Common Name (eg, your name or your server's hostname) []:xiaojin
Email Address []:123@qq.com Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456
An optional company name []:123456
[root@hadoop_node1 key]# cp server.key server.key.ori
[root@hadoop_node1 key]# openssl rsa -in server.key.ori -out server.key
Enter pass phrase for server.key.ori:
writing RSA key
[root@hadoop_node1 key]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
Signature ok
subject=/C=CN/ST=BJ/L=BJ/O=SDU/OU=SA/CN=xiaojin/emailAddress=123@qq.com
Getting Private key

4.修改nginx的配置文件

[root@hadoop_node1 conf]# cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name 10.0.0.71;
if ($scheme ~ http) {
return https://$server_name:8443$request_uri;
}
location / {
root html;
index index.html index.htm;
}
location = /50x.html {
root html;
}
}
server {
listen 8443 ssl http2 default_server;
server_name 10.0.0.71;
ssl_certificate key/server.crt;
ssl_certificate_key key/server.key;
location / {
root html;
index index.html index.htm;
}
location = /50x.html {
root html;
}
}
}
  • 检查防火墙是否开启,是否开启8443和80端口  
[root@hadoop_node1 conf]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@hadoop_node1 conf]# iptables -I INPUT -p tcp --dport 8443 -j ACCEPT
[root@hadoop_node1 conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.10.3/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.10.3/conf/nginx.conf test is successful
[root@hadoop_node1 conf]# /usr/local/nginx/sbin/nginx
[root@hadoop_node1 conf]# ss -lntup|grep 8
tcp LISTEN 0 128 *:80 *:* users:(("nginx",pid=7582,fd=6),("nginx",pid=7581,fd=6))
tcp LISTEN 0 128 *:22 *:* users:(("sshd",pid=1885,fd=3))
tcp LISTEN 0 128 *:8443 *:* users:(("nginx",pid=7582,fd=7),("nginx",pid=7581,fd=7))
tcp LISTEN 0 128 :::22 :::* users:(("sshd",pid=1885,fd=4))
  • 验证方法
  • 方法一
  1. 使用Chrome访问启用http2的站点,比如Jackie的环境为https://10.0.0.71:8443。
  2. 新开TAB页,在地址栏中输入chrome://net-internals/#http2,检查HTTP/2 sessions下的表格。
  3. 确认表格里是否出现了上一步访问的主机地址,比如10.0.0.71:8443。
  • 方法二
  1. 使用curl命令,参考HTTP/2 with curl,执行如下命令,确认站点返回的协议是否为HTTP
  2. curl --http2 -I 10.0.0.71:8443
  3. 如执行上述命令时遇到如下错误,说明系统当前安装的curl还不支持HTTP2协议。
  4. curl https://10.0.0.71:8443/ --http2 curl: (1) Unsupported protocol
  5. 可以执行如下命令,检查系统当前安装的curl支持的特性列表,确认是否包含HTTP2。
  6. 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
  7. 从前述输出信息可以了解到,当前安装的curl还不支持HTTP2。
  8. 这时可参考如何启用curl命令HTTP2支持重新编译curl,加入HTTP2的支持。
  • 方法三
  1. 安装Chrome插件HTTP/2 and SPDY indicator,安装完毕后访问启用HTTP2的站点,如果地址栏出现蓝色的闪电,说明站点已启用HTTP2。

  • Nginx跨域优化
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'POST,GET,OPTIONS';
add_header 'Access-Control-Allow-Headers' 'application/json,X-Requested-With,Content-Type,Accept';

  

nginx支持http2协议的更多相关文章

  1. 轻松让你的nginx服务器支持HTTP2协议

    目录 简介 HTTP1.1和HTTP2 安装最新的nginx 开启HTTP2支持 添加SSL支持 修改加密算法 Diffie–Hellman对消息进行加密 重定向所有的HTTP请求到HTTPS 启动n ...

  2. nginx支持HTTP2的配置过程

    一.获取安装包 http://zlib.net/zlib-1.2.11.tar.gz https://www.openssl.org/source/openssl-1.0.2e.tar.gz (ope ...

  3. Centos下nginx支持https协议

    1.首先配置nginx及其他插件,这个Google下,很多配置方案. 2.配置服务器的证书.操作步骤如下: [root@localhost ~]# cd /etc/pki/tls/certs [roo ...

  4. nginx安装http2.0协议

    1.HTTP2协议 HTTP 2.0 的主要目标是改进传输性能,实现低延迟和高吞吐量.从另一方面看,HTTP 的高层协议语义并不会因为这次版本升级而受影响.所有HTTP 首部.值,以及它们的使用场景都 ...

  5. Http2协议简介

    1.概述 和http1兼容.HTTP/2 没有改动 HTTP 的应用语义. HTTP 方法.状态代码.URI 和标头字段等核心概念一如往常. 不过,HTTP/2 修改了数据格式化(分帧)以及在客户端与 ...

  6. 【转】Linux下nginx配置https协议访问的方法

    一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...

  7. Linux下nginx配置https协议访问

    一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...

  8. Linux下nginx配置https协议访问的方法

    一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...

  9. 基于奇林软件kylinTOP工具的HTTP2协议的压力测试

    1.HTTP协议概述 说到http,那就应该先了解一下http协议的发展历史.关于http协议的历史,可以参考阮一峰老师的这篇博客文章HTTP 协议入门,里面介绍的比较详细了.简单来说http先后存在 ...

随机推荐

  1. Asp.Net Core 第05局:读取配置

    前言 本文介绍Asp.Net Core 读取配置文件. 环境 1.Visual Studio 2017 2.Asp.Net Core 2.2 开局 前期准备             1.添加app.j ...

  2. 记录之前工作用到费劲sql

    表为单独表,树结构 layer共有4层, 此sql为通过id list 查询出 layer = 2 的 id 个数 id , parent_id, layer SELECT COUNT(DISTINC ...

  3. Linux vsftpd服务配置以及三种验证方式以及常见错误解决办法

    文件传输协议(FTP): 文件传输协议(FTP,File Transfer Protocol),即能够让用户在互联网中上传.下载文件的文件协议,而FTP服务器就是支持FTP传输协议的主机,要想完成文件 ...

  4. JNDI 笔记

    原理:         在DataSource中事先建立多个数据库连接,保存在数据库连接池中.当程序访问数据库时,只用从连接池中取空闲状态的数据库连接即可,访问结束,销毁资源,数据库连接重新回到连接池 ...

  5. java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()Ljava/lang/Integer;

    java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()L ...

  6. git help

  7. js 模板引擎 -Art Template

    一个例子涵盖所有: <!doctype html> <html> <head> <meta charset="UTF-8"> < ...

  8. [HTML知识体系]meta标签的常见用法

    1.meta是什么 元素可提供有关页面的元信息(meta-information),比如针对搜索引擎和更新频度的描述和关键词. 标签位于文档的头部,不包含任何内容. 标签的属性定义了与文档相关联的名称 ...

  9. config.properties

    # 数据库配置db.host=10.100.2.50db.port=3306db.database=paycoredb.username=rootdb.password=mysql@123db.ini ...

  10. Jpa动态多表if多条件联合查询,并对查询结果进行分页

    public Page<Map<String, Object>> resourceList(TeachingInfo teachingInfo, Pageable pageab ...