欢迎来到梦飞科技

服务器租用

当前优惠活动:

Nginx升级到1.9.12并开启HTTP/2的详细步骤

一、筹备事情

昨天把站点从http进级到https,那么接下来就应该可以尝尝http/2的味道了!

可是今朝站点陈设在阿里云CentOS下,Nginx版本较量低,v1.4.4,所以必需得进级到v1.9.x,索性直接升到最新版得了!

安装之前,先筹备好两个目次:

# 下载的源码,放在这个目次下举办编译

# 编译后的App,安装到这个目次

mkdir -p /root/server

# 进入源码目次,筹备接下来的操纵

cd /root/source

二、下载openssl最新版源码

Openssl官方下载页面:这里

# 这里下载1.0.2g

wget http://www.openssl.org/source/openssl-1.0.2g.tar.gz

# 解压,备用

tar zxfv openssl-1.0.2g.tar.gz

三、下载zlib最新版源码

Zlib官方下载页面:这里

# 这里下载1.2.8

wget -O - http://prdownloads.sourceforge.net/libpng/zlib-1.2.8.tar.gz\?download > zlib-1.2.8.tar.gz

# 解压,备用

tar zxfv zlib-1.2.8.tar.gz

四、下载Nginx最新版源码

Nginx官方下载页面:这里

# 这里下载1.9.12

wget http://nginx.org/download/nginx-1.9.12.tar.gz

# 解压

tar zxfv nginx-1.9.12.tar.gz

五、编译Nginx

这里有个原则,就是:

当前低版本的Nginx已有的modules,都需要保存,万一丢了谁,一会儿新版本跑不起来就悲催了!

1、获取当前低版本Nginx的编译参数

# -V参数获取具体信息

/root/server/nginx-1.4.4/sbin/nginx -V

获得功效:

nginx version: nginx/1.4.4

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)

configure arguments: --user=www --group=www --prefix=/root/server/nginx-1.4.4 --with-http_stub_status_module --without-http-cache --with-http_gzip_static_module

2、增加新参数

--with-openssl=/root/source/openssl-1.0.2g --with-pcre --with-zlib=/root/source/zlib-1.2.8 --with-stream --with-stream_ssl_module --with-http_v2_module --with-threads    

3、编译&安装

cd nginx-1.9.12

# 编译

./configure --user=www --group=www --prefix=/root/server/nginx-1.9.12 --with-http_stub_status_module --without-http-cache --with-http_gzip_static_module --with-openssl=/root/source/openssl-1.0.2g --with-pcre --with-zlib=/root/source/zlib-1.2.8 --with-stream --with-stream_ssl_module --with-http_v2_module --with-threads

# 安装

make && make install

并没有什么[Error]之类的错误信息,编译安装乐成!

4、新版本测试

# 查察安装后的信息

/root/server/nginx-1.9.12/sbin/nginx -V

# 测试

/root/server/nginx-1.9.12/sbin/nginx -t

安心了,确实乐成了!

六、Nginx设置文件移植

即便Nginx版本从1.4.4到1.9.12超过了那么多,但我根基可以猜到,设置文件必定没啥非凡的大行动,所以直接cp移植,测试即可!

# 从本来的nginx/conf目次移植

cp /root/server/nginx-1.4.4/conf/nginx.conf /root/server/nginx-1.9.12/conf/nginx.conf

cp -r /root/server/nginx-1.4.4/conf/vhost /root/server/nginx-1.9.12/conf/

# 测试

/root/server/nginx-1.9.12/sbin/nginx -t

nginx: the configuration file /root/server/nginx-1.9.12/conf/nginx.conf syntax is ok

nginx: configuration file /root/server/nginx-1.9.12/conf/nginx.conf test is successful

完美,根基无缝移植!

七、启用新版本Nginx

# 温柔的遏制老版本nginx,虽然,也可以采纳暴力的 pkill nginx 方法

service nginx stop

# 启用新版本nginx

/root/server/nginx-1.9.12/sbin/nginx

会见网站 https://www.server110.com,一切正常!可以修改软连了:

# 移除老的软连,成立新的软连

unlink /root/server/nginx && ln -s /root/server/nginx-1.9.12 /root/server/nginx

八、回归正题--开启http2

这一步,就已经变得很是简朴了,郑州电信服务器 服务器托管,修改nginx/conf/vhosts/baidufe.conf即可:

server {

    listen 443 ssl http2;

    server_name  baidufe.com www.server110.com;

    ...

}

其实,也就是直接在listen 443 ssl后头增加http2即可!然后nginx reload,搞定!

九、网站http2验证

进入 https://www.server110.com刷新,右上角HTTP/2 and SPDY indicator图标变蓝色了,验证通过!

虽然,还可以通过curl的方法来检测,可是前提条件是,curl的版本得足够新!

curl --http2 -I https://www.server110.com

至此,大功告成!

梦飞科技 - 全球数据中心基础服务领先供应商

Copyright © 2003-2019 MFISP.COM. 国外服务器租用 IDC公司 版权所有 粤ICP备11019662号