Nginx 安装与基本操作指南

Nginx 安装与基本操作指南

Nginx 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器。本文将介绍如何在 Linux 系统上安装 Nginx,以及一些基本的操作和配置解析。

安装 Nginx

在 Ubuntu 上安装 Nginx

  1. 更新软件包列表:

    sudo apt update
    
  2. 安装 Nginx:

    sudo apt install nginx
    
  3. 启动 Nginx 服务:

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

    sudo systemctl enable nginx
    

在 CentOS 上安装 Nginx

  1. 添加 Nginx 仓库:

    sudo yum install epel-release
    sudo yum install nginx
    
  2. 启动 Nginx 服务:

    sudo systemctl start nginx
    
  3. 设置 Nginx 开机自启动:

    sudo systemctl enable nginx
    

基本操作

启动 Nginx

sudo systemctl start nginx

停止 Nginx

sudo systemctl stop nginx

重启 Nginx

sudo systemctl restart nginx

重新加载 Nginx 配置

sudo systemctl reload nginx

检查 Nginx 状态

sudo systemctl status nginx