1. 下载nginx并解压

wget http://nginx.org/download/nginx-1.12.2.tar.gz
#解压
tar -zxvf nginx-1.5.9.tar.gz 

2. 配置

./configure --prefix=/usr/local/nginx 
# prefix表示待会make安装时候的目录
#在配置信息的时候,也就是在第三步,出现了一下错误:
#错误为:
./configure: error: the HTTP rewrite module requires the PCRE library.
#安装pcre-devel解决问题
yum -y install pcre-devel

#还有可能出现:
#错误提示:
./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library.   You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.
#解决办法:
yum -y install openssl openssl-devel

#以及错误提示:
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
#解决办法
yum install -y zlib-devel

3. 编译安装

make 编译 (make的过程是把各种语言写的源码文件,变成可执行文件和各种库文件)

make install 安装 (make install是把这些编译出来的可执行文件和库文件复制到合适的地方)

make && make install

make: *** No rule to make target build, needed by default. Stop.这种现象、迩回头看看./configure的出错信息是不是没装某个组件、比如没装

4.验证安装,配置环境变量

cd /usr/local/nginx/sbin
./nginx -v
#如果出现版本信息则代表成功
vi /etc/profile
#nginx configure
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
#使配置生效
source /etc/profile
#此时再次查看
nginx -v