Blog

Blog

PHODAL

Nginx HTTP2 编译

看到了一些关于HTTP2的传闻,于是就想着升级网站的Nginx,让他支持HTTP2.0,顺便也编译一下新的ngx_pagespeed,也是有近一年没有更新nginx了。

前提:

  1. 需要https证书
  2. 需要有OpenSSL 1.0.2+

安装

以下步骤适合于LNMP安装。

1.下载Nginx

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

2.下载和编译

 tar xvfz nginx-1.9.4.tar.gz
 cd nginx-1.9.4

3.打patch

wget http://nginx.org/patches/http2/patch.http2.txt
 patch -p1 < patch.http2.txt

4.配置

./configure --with-http_ssl_module \
      --with-http_v2_module \
      --with-debug \
      --with-openssl=/path/to/openssl-1.0.2

如果你和我一样有各种模块,那么配置可能是下面这样子的

./configure --user=www --group=www --add-module=../ngx_pagespeed-release-1.9.32.6-beta --prefix=/usr/local/nginx --with-pcre --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-ipv6

5.编译

make

6.修改配置如下

 server {
     listen 443 default_server ssl http2;

     ssl_certificate      server.crt;
     ssl_certificate_key  server.key;

     ...
 }

7.更新

mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
cp objs/nginx /usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx -t
make upgrade

8.查看

chrome://net-internals/#http2

接着搜索phodal.com就有了~~

Nginx HTTP2

关于我

Github: @phodal     微博:@phodal     知乎:@phodal    

微信公众号(Phodal)

围观我的Github Idea墙, 也许,你会遇到心仪的项目

QQ技术交流群: 321689806
comment

Feeds

RSS / Atom

最近文章

关于作者

Phodal Huang

Engineer, Consultant, Writer, Designer

ThoughtWorks 技术专家

工程师 / 咨询师 / 作家 / 设计学徒

开源深度爱好者

出版有《前端架构:从入门到微前端》、《自己动手设计物联网》、《全栈应用开发:精益实践》

联系我: h@phodal.com

微信公众号: 最新技术分享

标签