**
nginx使用http2,并配置ssl证书
**
想要使用http2,需要在安装nginx时安装http2模块和ssl模块
前置条件nginx版本需要在1.9.5以上
#解压nginx包
tar -zxvf nginx-1.18.0.tar.gz
#进入nginx目录
cd nginx-1.18.0
#执行
./configure --prefix=/usr/local/nginx --with-http_v2_module --with-http_ssl_module
#这里若出现报错提示以下信息:
#/configure: error: SSL modules require the OpenSSL library.
#You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-openssl= option.
#说明未安装Openssl
#可通过yum安装
yum install openssl openssl-devel -y
#安装完成后再次执行./configure --prefix=c --with-http_v2_module --with-http_ssl_module
#然后执行
make && make install
#编译完成之后进入nginx目录
cd /usr/local/nginx/conf
#编辑nginx.conf
server {
listen 443 ssl http2;
server_name tiansl.cn;
ssl_certificate /usr/local/nginx/zhengshu/tiansl.cn.pem;
ssl_certificate_key /usr/local/nginx/zhengshu/tiansl.cn.key;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#保存退出后启动nginx
../sbin/nginx
#到页面上验证是否开启了http2
打开network,右键点击竖线,选择Protocol
显示h2则表示开启了http2