# 一、 nginx 安装
## 1. nginx 官网版本介绍
nginx下载地址:http://nginx.org/en/download.html
Nginx官网提供了三个类型的版本:
> Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以说是开发版
> Stable version:最新稳定版,生产环境上建议使用的版本
> Legacy versions:遗留的老版本的稳定版
## 2. 安装环境
> Nginx 1.20.1
> CentOS Linux release 8.4.2105
## 3. Nginx 下载
a. 创建nginx文件夹 mkdir nginx
b. 进入nginx文件夹 cd nginx
c. 使用wget命令下载nginx
```
[test@slavel ~]$ mkdir nginx
[test@slavel ~]$ cd nginx/
[test@slavel nginx]$ wget http://nginx.org/download/nginx-1.20.1.tar.gz
```
> 注:没有wget命令,先使用yum install wget 安装
## 4. Nginx 安装
a. 解压
```
[test@slave1 nginx]$ tar -zxvf nginx-1.20.1.tar.gz
[test@slave1 nginx]$ cd nginx-1.20.1
```
b. 安装
```
[test@slave1 nginx-1.20.1]$ ./configure
```
> 当输入命令出现下面的问题时,需要安装pcre库
```
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=
```
> 使用yum 安装pcre
```
[test@slave1 nginx-1.20.1]$yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
Installed:
zlib-devel-1.2.11-17.el8.x86_64
pcre-cpp-8.42-4.el8.x86_64 pcre-devel-8.42-4.el8.x86_64 pcre-utf16-8.42-4.el8.x86_64 pcre-utf32-8.42-4.el8.x86_64
Complete!
```
> pcre安装完成,继续nginx的安装
```
[test@slave1 nginx-1.20.1]$ ./configure
[test@slave1 nginx-1.20.1]$ make
[test@slave1 nginx-1.20.1]$ make install
```
## 5. 启动Nginx
进入Nginx 安装目录的sbin目录,启动Nginx
```
[test@slave1 nginx-1.20.1]$ cd /usr/local/nginx/sbin
[test@slave1 sbin]$ sudo ./nginx &
[1] 81851
```
## 6. 验证 Nginx 是否启动成功
```
[test@slave1 sbin]# curl localhost
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.
For online documentation and support please refer to
nginx.org.
Commercial support is available at
nginx.com.
Thank you for using nginx.
```



