安装前准备

安装基本工具

1
2
yum -y update
yum -y groupinstall "Development Tools"

安装依赖

注: brotli 只能通过编译进行安装

方案1 使用 yum 进行安装

1
yum -y install openssl-devel pcre-devel zlib-devel

方案2 编译安装

PCRE

1
wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gztar -zxvf pcre-8.42.tar.gz

zlib

1
wget https://www.zlib.net/zlib-1.2.11.tar.gztar zxvf zlib-1.2.11.tar.gz

OpenSSL

1
wget https://www.openssl.org/source/openssl-1.1.1a.tar.gztar zxvf openssl-1.1.1a.tar.gz

brotli

1
git clone https://github.com/google/ngx_brotli.gitcd ngx_brotligit submodule update --initcd ..

安装 Nginx

编译 Nginx

1
wget https://nginx.org/download/nginx-1.14.2.tar.gztar -zxvf nginx-1.14.2.tar.gzcd nginx-1.14.2./configure \--prefix=/usr/local/bin/nginx14/ \--with-pcre=/usr/local/src/pcre-8.42 \--with-openssl=/usr/local/src/openssl-1.1.1a \--with-zlib=/usr/local/src/zlib-1.2.11 \--add-module=/usr/local/src/ngx_brotli \--with-http_realip_module \--with-http_ssl_module \--with-http_v2_modulemake && make install# 可以酌情考虑使用make -j2 && make install

Nginx 配置

创建 nginx.service

1
cat <<EOF > /lib/systemd/system/nginx.service[Unit]Description=The NGINX HTTP and reverse proxy serverAfter=syslog.target network.target remote-fs.target nss-lookup.target[Service]Type=forkingPIDFile=/usr/local/bin/nginx14/logs/nginx.pidExecStartPre=/usr/local/bin/nginx14/sbin/nginx -tExecStart=/usr/local/bin/nginx14/sbin/nginxExecReload=/usr/local/bin/nginx14/sbin/nginx -s reloadExecStop=/bin/kill -s QUIT $MAINPIDPrivateTmp=true[Install]WantedBy=multi-user.targetEOF