根据相关法律法规,本站不对欧盟用户提供服务。

MENU

Ubuntu 14.04 编译安装支持 HTTP2 的 Nginx

November 14, 2016 • Read: 762 • 代码

据说 HTTP2 对访问速度有神秘加成,正好晚上有空,就来折腾一下。

根据网上搜到的文章,添加了好几个所谓的最新 Nginx 源均失败,有些是因为速度太慢连不上,有些是提供的 Nginx 包是基于 openssl 1.0.1 版本,该版本不能完全支持 HTTP2。

只好从源码编译了。

首先安装依赖:

apt install nginx-common libxslt1-dev libgd-dev libgeoip-dev libpcre3-dev

下载 Nginx 及相关包源码:

# Create temporary work area
mkdir /tmp/nginx
cd /tmp/nginx

# Download and extract nginx
wget http://nginx.org/download/nginx-1.9.5.tar.gz
tar xf nginx-1.9.5.tar.gz

# Download and extract OpenSSL
wget https://www.openssl.org/source/openssl-1.0.2d.tar.gz
tar xf openssl-1.0.2d.tar.gz

# Download and extract gzip
wget http://zlib.net/zlib-1.2.8.tar.gz
tar xf zlib-1.2.8.tar.gz

# Delete downloads
rm *.tar.gz

# Download ngx_http_substitutions_filter_module
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module

编译安装:

cd nginx-1.9.5

./configure \
--with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' \
--with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' \
--sbin-path=/usr/sbin/nginx \
--prefix=/usr/share/nginx \
--conf-path=/etc/nginx/nginx.conf \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log \
--lock-path=/var/lock/nginx.lock \
--pid-path=/run/nginx.pid \
--http-client-body-temp-path=/var/lib/nginx/body \
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
--http-proxy-temp-path=/var/lib/nginx/proxy \
--http-scgi-temp-path=/var/lib/nginx/scgi \
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
--with-debug \
--with-pcre-jit \
--with-ipv6 \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_dav_module \
--with-http_geoip_module \
--with-http_gzip_static_module \
--with-http_image_filter_module \
--with-http_v2_module \
--with-http_sub_module \
--with-http_xslt_module \
--with-mail \
--with-mail_ssl_module \
--with-http_sub_module \
--with-zlib=../zlib-1.2.8 \
--with-openssl=../openssl-1.0.2d \
--add-module=../ngx_http_substitutions_filter_module

make 
make install

HTTP2 配置:

listen    443 ssl http2;

参考资料:Github 一键安装脚本

Tags: vps
Archives QR Code
QR Code for this page
Tipping QR Code
Leave a Comment