服务器上部署Nginx的几种方式

在服务器上部署 Nginx 有多种方式,具体取决于你的操作系统和偏好。以下是几种常见的部署方式:

1. 使用包管理器安装

这是最常见和推荐的方式,适用于大多数 Linux 发行版。

1.1 在 Ubuntu/Debian 上使用 apt
  1. 更新包列表

    sudo apt update
    
  2. 安装 Nginx

    sudo apt install nginx
    
  3. 启动 Nginx 服务

    sudo systemctl start nginx
    
  4. 设置开机自启动

    sudo systemctl enable nginx
    
  5. 检查 Nginx 状态

    sudo systemctl status nginx
    
1.2 在 CentOS/RHEL 上使用 yumdnf
  1. 更新包列表

    sudo yum update  # 或 sudo dnf update
    
  2. 安装 Nginx

    sudo yum install nginx  # 或 sudo dnf install nginx
    
  3. 启动 Nginx 服务

    sudo systemctl start nginx
    
  4. 设置开机自启动

你可能感兴趣的:(服务器,服务器,nginx,运维)