编译安装Nginx

安装依赖

首先安装依赖库和编译要用到的工具:

1
sudo apt-get install build-essential libpcre3 libpcre3-dev zlib1g-dev unzip git

获取必要组件

1
2
mkdir nginx    //新建文件夹,用于存放编译nginx所需的组件
cd nginx

ngx_brotli

1
2
3
4
git clone https://github.com/google/ngx_brotli.git
cd ngx_brotli
git submodule update --init
cd ../

OpenSSL

1
2
wget https://www.openssl.org/source/openssl-1.1.1-pre9.tar.gz
tar zxf openssl-1.1.1-pre9.tar.gz

pcre

1
2
wget https://ftp.pcre.org/pub/pcre/pcre-8.42.zip
unzip pcre-8.42.zip

zlib

1
2
wget https://zlib.net/zlib-1.2.11.tar.gz
tar zxf zlib-1.2.11.tar.gz

编译并安装 Nginx

1
2
3
4
5
6
wget https://nginx.org/download/nginx-1.14.0.tar.gz
tar zxf nginx-1.14.0.tar.gz
cd nginx-1.14.0
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --add-module=../ngx_brotli --with-openssl=../openssl-1.1.1-pre9 --with-openssl-opt='enable-tls1_3 enable-weak-ssl-ciphers' --with-pcre=../pcre-8.42 --with-pcre-jit --with-ld-opt=-ljemalloc --with-zlib=../zlib-1.2.11
make
sudo make install