服务器上部署Nginx的几种方式
在服务器上部署 Nginx 有多种方式,具体取决于你的操作系统和偏好。以下是几种常见的部署方式:
1. 使用包管理器安装
这是最常见和推荐的方式,适用于大多数 Linux 发行版。
1.1 在 Ubuntu/Debian 上使用 apt
-
更新包列表
sudo apt update
-
安装 Nginx
sudo apt install nginx
-
启动 Nginx 服务
sudo systemctl start nginx
-
设置开机自启动
sudo systemctl enable nginx
-
检查 Nginx 状态
sudo systemctl status nginx
1.2 在 CentOS/RHEL 上使用 yum
或 dnf
-
更新包列表
sudo yum update # 或 sudo dnf update
-
安装 Nginx
sudo yum install nginx # 或 sudo dnf install nginx
-
启动 Nginx 服务
sudo systemctl start nginx
-
设置开机自启动