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@rbtnode1 ~]# /usr/local/nginx/sbin/nginx -V   查看当前手动安装的模块
    nginx version: nginx/1.14.2
    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: --with-http_ssl_module --with-stream --with-http_stub_status_module --with-http_v2_module
    You have new mail in /var/spool/mail/root
    [root@rbtnode1 ~]#

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的配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[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端口  
1
2
3
4
5
6
7
8
9
10
11
[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跨域优化
1
2
3
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.0协议的更多相关文章

  1. 【HTTP】402- 深入理解http2.0协议,看这篇就够了!

    本文字数:3825字 预计阅读时间:20分钟 导读 http2.0是一种安全高效的下一代http传输协议.安全是因为http2.0建立在https协议的基础上,高效是因为它是通过二进制分帧来进行数据传 ...

  2. HTTP2.0协议

    HTTP2.0协议 http2协议的草案已经出来了,阅读了一下网上的中文版,http2尽可能的兼容http1.1.改进了http1.1协议的不足. http1.0和http1.1的缺点: 1.http ...

  3. gRPC【RPC自定义http2.0协议传输】

    gRPC 简介 gRPC是由Google公司开源的高性能RPC框架. gRPC支持多语言 gRPC原生使用C.Java.Go进行了三种实现,而C语言实现的版本进行封装后又支持C++.C#.Node.O ...

  4. 既有Nginx重新动态编译增加http2.0模块

    1.HTTP2.0 HTTP2.0相较于http1.x,大幅度的提升了web性能,在与http1.1完全语义兼容的基础上,进一步减少了网络延时.我们现在很多对外的网站都采用https,但是F12一下看 ...

  5. Nginx http2.0

    109/110 HTTP2.0协议 优势必须使用TLS加密 传输数据量大幅减少 1:以二进制格式传输  2:标头压缩(header做压缩) 多路复用及相关功能 : 消息优先级 (比如样式表先渲染页面那 ...

  6. HTTP2.0学习 与 Nginx和Tomcat配置HTTP2.0

    目录 一.HTTP2.0 1.1 简介 1.2 新的特性 1.3 h2c 的支持度 二.Nginx 对 http2.0 的支持 2.1 Nginx 作为服务端使用http2.0 2.2 Nginx 作 ...

  7. HTTP,HTTP2.0,SPDY,HTTPS你应该知道的一些事

    作为一个经常和web打交道的程序员,了解这些协议是必须的,本文就向大家介绍一下这些协议的区别和基本概念,文中可能不局限于前端知识,还包括一些运维,协议方面的知识,希望能给读者带来一些收获,如有不对之处 ...

  8. HTTP2.0那些事

    1. HTTP2.0的前世 http2.0的前世是http1.0和http1.1这两兄弟.虽然之前仅仅只有两个版本,但这两个版本所包含的协议规范之庞大,足以让任何一个有经验的工程师为之头疼.http1 ...

  9. HTTP2.0和QUIC

    最近看到腾讯云支持QUIC的文章,突然意识到还没有好好认识HTTP2.QUIC,而要认识HTTP2,就需要从HTTP1.0开始讲起,才能清楚HTTP的发展历程. HTTP1.x HTTP(HyperT ...

随机推荐

  1. Luogu P1198 BZOJ 1012 最大数 (线段树)

    手动博客搬家: 本文发表于20170821 14:32:05, 原地址https://blog.csdn.net/suncongbo/article/details/77449455 URL: (Lu ...

  2. 【Codeforces 342A】Xenia and Divisors

    [链接] 我是链接,点我呀:) [题意] [题解] 最后a,b,c只有以下3种情况 1,2,4 1,2,6 1,3,6 那么用cnt[8]统计每个数字出现的次数. 输出cnt[4]次1,2,4 (如果 ...

  3. hdu 2586 lca在线算法(朴素算法)

    #include<stdio.h> #include<string.h>//用c/c++会爆栈,用g++ac #define inf 0x3fffffff #define N ...

  4. EXPLAIN sql优化方法(1) 添加索引

    添加索引优化器更高效率地执行语句 假设我们有两个数据表t1和t2,每个有1000行,包含的值从1到1000.下面的查询查找出两个表中值相同的数据行: mysql> SELECT t1.i1, t ...

  5. SQL SERVER高级知识积累

    什么叫做高可用服务器? 高可用服务器简单来理解就是不宕机的服务器 什么叫走服务器的自动化灾备? 自动灾备的意思就是,让从服务器自动变成主服务器 sql server的聚合是什么? 事务会引起性能下降, ...

  6. C#--线程池与线程的种类

    .NET CLR线程的种类 至少3个线程:主线程.调试线程.终结器线程 1.main thread 2.worker thread 3.finalizer thread 4.debugger help ...

  7. expdp impdp 数据库导入导出命令具体解释

    一.创建逻辑文件夹,该命令不会在操作系统创建真正的文件夹.最好以system等管理员创建. create directory dpdata1 as 'd:\test\dump'; 二.查看管理理员文件 ...

  8. 轻快的vim(四):修改

    我想每个Coder都深刻的明白,修改这一操作在代码的世界里是多么重要 与其说修改,无非就是删除了再插入,但VIM把这两者结合的很有效率 闲话少说,让我们再次使用这轻快的VIM在code上起舞 字符替换 ...

  9. CodeForces 596A

    Description After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the ...

  10. JavaScript Simple

    ylbtech-JavaScript: 1.返回顶部 1.   2. 2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http: ...