码迷,mamicode.com
首页 > Web开发 > 详细

http2 技术整理 nginx 搭建 http2

时间:2019-10-13 12:39:00      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:default   dex   源码编译安装   configure   cat   cgi   timeout   php   安装   

使用 nginx 搭建一个 http2 的站点,准备所需:

1,域名 .com .net 均可(国内域名需要 icp 备案)

2,云主机一个,可以自由的安装配置软件的服务器

3,https 证书

http2 基于 https ,所以先配置好 https 访问

本文以 阿里云 ecs 操作系统 CentOS 6.5 (以下教程针对有 linux 使用基础的人,本文不会介绍 ,安装 编译环境,yum 软件包这种基础的东西)

购买 https 证书,淘宝上就可以买,价格几十到几千不等。

使用源码编译安装  nginx http://nginx.org/en/download.html

使用目前的最新版 nginx-1.14.2.tar.gz

nginx http2 模块支持,需要用到 openssl 1.0.2 http://nginx.org/en/docs/http/ngx_http_v2_module.html

先下载一个 openssl-1.0.2j.tar.gz 解压

开始编译 nginx 并启用 ssl http2 模块

./configure --with-http_ssl_module --with-http_v2_module --prefix=/usr/local/nginx/ --with-openssl=/home/openssl-1.0.2j
make && make install

运行 nginx -V 查看版本及支持

/usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.14.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
built with OpenSSL 1.0.2j 26 Sep 2016
TLS SNI support enabled
configure arguments: --with-http_ssl_module --with-http_v2_module --prefix=/usr/local/nginx/ --with-openssl=/home/openssl-1.0.2j

配置 ssl http2 

/usr/local/nginx/conf/ssl
将购买的证书放到这里
xxx.com.key xxx.com.pem

vi /usr/local/nginx/conf/nginx.conf
listen 443 ssl http2; # 1.1版本后这样写

server_name www.xxx.com; #填写绑定证书的域名

ssl_certificate /usr/local/nginx/conf/ssl/xxx.com.pem; # 指定证书的位置,绝对路径
ssl_certificate_key /usr/local/nginx/conf/ssl/xxx.com.key; # 绝对路径,同上
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配置
ssl_prefer_server_ciphers on;

使用 火狐浏览器访问(火狐可以更好的显示出来头信息)

技术图片

添加 php7 支持

./configure --prefix=/usr/local/php7 --with-pcre-dir --enable-mysqlnd --with-zlib-dir --enable-zip --with-libxml-dir \
--with-iconv-dir --with-openssl-dir --with-freetype-dir --enable-gd-jis-conv --with-gd --with-curl --enable-fpm --enable-mbstring

cd /usr/local/php7/etc
cp php-fpm.conf.default php-fpm.conf

cd /usr/local/php7/etc/php-fpm.d
mv www.conf.default www.conf

修改 nginx.conf
location ~ \.php$ {
root /usr/local/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name;
include fastcgi_params;
}


/usr/local/php7/sbin/php-fpm

/usr/local/nginx/sbin/nginx -s reload

技术图片

 

http2 技术整理 nginx 搭建 http2

标签:default   dex   源码编译安装   configure   cat   cgi   timeout   php   安装   

原文地址:https://www.cnblogs.com/ningci/p/11665520.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!