ubuntu 手动编译安装nginx-1.13.3支持http2

1、下载 nginx, openssl, zlib,解压到同一文件夹下

nginx-1.13.2

openssl 1_0_2l

zlib-1.2.11

2、安装pcre

sudo apt-get install libpcre3 libpcre3-dev

3、通过shell脚本编译安装nginx

#!/bin/sh

PREFIX=/usr/local/nginx

if [ ! -d $PREFIX ]
then
    sudo mkdir -p $PREFIX
fi

./configure --prefix=$PREFIX \
    --with-openssl=../openssl-OpenSSL_1_0_2l \
    --with-pcre \
    --with-zlib=../zlib-1.2.11 \
    --with-stream \
    --with-stream_ssl_module \
    --with-http_ssl_module \
    --with-http_v2_module \
    --with-threads

make 
sudo make install                                                                                                                                     

4、启动nginx

cd /usr/local/nginx/sbin
sudo ./nginx

5、openssl 生成 server.key 与 server.crt

 /usr/local/nginx/conf

下创建shell脚本 configure_key.sh

#!/bin/sh

openssl genrsa -des3 \
    -out server.key \
    1024

openssl req -new -key server.key -out server.csr

cp server.key server.key.org

openssl rsa -in server.key.org -out server.key

openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

添加执行权限并执行

sudo chmod +x configure_key.sh
./configure_key.sh

6、修改nginx配置

进入nginx安装目录下的conf文件夹,修改nginx.conf

    server {
          listen       443 ssl http2;
          server_name  localhost;
  
          ssl_certificate server.crt;
          ssl_certificate_key server.key;
          #charset koi8-r;
          # 以下省略

重启nginx

cd /usr/local/nginx/sbin
sudo ./nginx -s reopen

7、安装chrome 插件 HTTP/2 and SPDY indicator 访问https://localhost:443/

ubuntu 手动编译安装nginx-1.13.3支持http2_第1张图片
Screen Shot 2017-07-20 at 3.38.44 PM.png

右上角有一个闪电形状的小标志,呈现蓝色就表明当前网页服务采用http2协议

你可能感兴趣的:(ubuntu 手动编译安装nginx-1.13.3支持http2)