0%

nginx安装

版本介绍

源码编译安装

1. 下载安装包方式

  • 官网直接下载http://nginx.org/en/download.html

  • 使用wget命令下载(推荐)。确保系统已经安装了wget,如果没有安装,执行 yum install wget 安装wget -c https://nginx.org/download/nginx-1.18.0.tar.gz

2. 解压

1
tar -zxvf nginx-1.18.0.tar.gz

3. yum安装依赖项

1
2
3
#gcc安装,nginx源码编译需要;pcre-devel 安装,nginx 的 http 模块使用 pcre 来解析正则表达式;zlib安装,nginx 使用zlib对http包的内容进行gzip

yum install gcc pcre-devel zlib-devel

4. 配置

1
2
3
4
cd /usr/local/nginx/nginx-1.18.0

#使用默认配置
./configure

5. 编译安装

1
make && make install

6. 启动、停止nginx

1
2
3
4
5
cd /usr/local/nginx/sbin/
./nginx
./nginx -s stop
./nginx -s quit
./nginx -s reload

Yum安装

安装yum

1
yum install yum-utils

添加yum安装源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
vim /etc/yum.repos.d/nginx.repo

#添加以下内容
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

安装

1
yum install nginx

命令

1
2
3
4
systemctl status nginx
systemctl start nginx
systemctl restart nginx
systemctl stop nginx