栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

nginx 安装

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

nginx 安装

# 一、 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= option.
```

> 使用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



Welcome to nginx!

    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.



```

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/277807.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号