开发者社区> 问答> 正文

在 Nginx 上部署 HTTP/2



[attachment=87653]


内容
apache 在这里: 在 Apache 上部署 HTTP/2
[attachment=87651][attachment=87652]

这里我们用 CHACHA20 的加密方式,所以这里我们将 openssl 替换为比较黑科技的分支 LibreSSL,LibreSSL 是在心血漏洞后由 OpenBSD 创建的分支比谷歌的 BoringSSL 使用难得要小一些。LibreSSL 还有一个方便的地方就是不需要我们去编译,nginx 自己会编译的。



准备


./configure 参数中加入
--with-openssl=/path/to/libressl-2.3.0 --with-http_v2_module --with-http_ssl_module

当然了,对新手来说还是太笼统了,所以我再详细介绍一下。
首先我们下载,LibreSSL:
cd /root
wget -c http://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-2.3.0.tar.gz  // 最好进入目录看看有没有更新的版本,有就下载更新的版本
tar xzf libressl-2.3.0.tar.gz  // 如果有新的版本,这里也要改版本号
mv libressl-2.3.0 libressl  //将目录重命名为 libressl,为了方便未来升级 nginx,如果 libressl 也有变动,那么就就只要在这个目录下,删除旧的上传新的。



接着,我们下载 nginx:
出这篇文章的时候,刚好出 1.9.6,所以我们就用 1.9.6 了,如果有新的,务必也下载新版本。
wget http://nginx.org/download/nginx-1.9.6.tar.gz
tar xzf nginx-1.9.6.tar.gz && cd nginx-1.9.6



编译


这是我原来的参数,
./configure --prefix=$nginx_install_dir --user=$run_user --group=$run_user --with-http_stub_status_module --with-http_spdy_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module $malloc_module

我们去掉 spdy,改为 h2,并且加入 libressl 参数:
./configure --prefix=$nginx_install_dir --user=$run_user --group=$run_user --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-openssl=/root/libressl --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module $malloc_module

然后新安装的就安装,升级的就升级,不再累述。
然后耐心等待,nginx 会自动编译 libressl。

配置


现在我们要配置 h2 和 CHACHA20 的加密方式了。
在 443 端口的位置,去掉 spdy,加入 h2
listen 443 ssl http2 default_server;

注意,如果你以前设置过 spdy,请删除所有和 spdy 有关的参数!
ssl_ciphers 的最前面加入
ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:

最后


最后么,还是那句老话,不要忘记重启 nginx,如果不会就直接重启系统。


来自: https://www.vobe.io/396

展开
收起
妙正灰 2015-10-30 12:37:27 9815 0
1 条回答
写回答
取消 提交回答
  • 阿里云论坛版主,伪Linux运维,完美主义者。
    这个是ie下有没有报错!灰灰?
    2015-11-01 22:36:18
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
CDN助力企业网站进入HTTPS时代 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载