1. 安装依赖环境

在安装 nginx 之前,需要先安装编译器和依赖库,可以使用 yum 命令安装,命令如下:

12
Bash
sudo yum -y install gcc-c++sudo yum -y install pcre pcre-devel
Bash

2. 下载 nginx

从 nginx 官网下载最新的稳定版本,比如我们使用 nginx-1.14.0.tar.gz,下载完成后,将文件放到 /usr/local/src/ 目录下,然后解压:

123
Bash
cd /usr/local/src/tar -zxvf nginx-1.14.0.tar.gzcd nginx-1.14.0
Bash

3. 编译安装

在解压后的文件夹下,执行如下命令:

12345678
Bash
./configure --prefix=/usr/local/nginx--user=www --group=www--with-http_stub_status_module--with-http_ssl_module--with-http_gzip_static_module--with-pcremakemake install
Bash

编译安装完成后,在 /usr/local/nginx/sbin/nginx 即可启动 nginx 服务。