哈喽,大家好哇!
我是小爱同学,欢迎大家阅读我的文章!
今天小爱同学给大家带来nginx WEB服务器开启http/2.0的教程,一起来看看吧!
HTTP/2 (原名HTTP/2.0)即超文本传输协议 2.0,是下一代HTTP协议。是自1999年http1.1发布后的首个更新。HTTP 2.0在2013年8月进行首次合作共事性测试。在开放互联网上HTTP 2.0将只用于https://网址,而 http://网址将继续使用HTTP/1,目的是在开放互联网上增加使用加密技术,以提供强有力的保护去遏制主动攻击。——摘自百度百科
大概就是,http/2只能用于SSL保护的网站不能用于http/1不安全的网站。增强SSL保护,降低安全风险!接下来教大家如何开启nginx http/2。
注意
需要注意的是,开启http/2需要nginx版本在1.10以上,openssl版本1.0.2以上。
下载nginx源码文件。点击这里下载
增加编译http2模块
http_v2_module
查看原有模块
/opt/software/nginx/sbin/nginx -V
已安装模块
configure arguments: --prefix=/opt/software/nginx --with-http_stub_status_module --with-http_ssl_module
切换到源码文件夹
cd /opt/software/nginx-1.16.0
在原有的模块基础上编译http2
./configure --prefix=/opt/software/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module
运行上面的命令即可,等配置完
配置完成后,运行命令
make
注意
这里不要进行 make install,否则就是覆盖安装。
备份Nginx
cp /opt/software/nginx/sbin/nginx /opt/software/nginx/sbin/nginx.bak
覆盖Nginx
查看nginx进程
ps -ef |grep nginx
杀死进程
kill -QUIT [nginx master pid]
注意
关闭 nginx master 进程,注意修改上面pid的参数。
覆盖nginx
cd /opt/software/nginx-1.16.0
cp ./objs/nginx /opt/software/nginx/sbin/
验证查看安装模块
cd /opt/software/nginx/sbin
./nginx -V
nginx开启http2
ps:
开启HTTP2服务非常简单,只需要在端口443后面添加http2即可。
server {
server {
listen 443 http2;
...
}
点击这里验证http2