Ubuntu教程

Ubuntu 安装Nginx

如何在 Ubuntu 16.04 LTS 上安装 Nginx?

简介

Nginx 是一个开源的 HTTP 网络服务器。它由 Igor Sysoev 创建并于 2004 年发布。我们可以使用它来部署 Web 应用程序。
在本教程中,我们将在 Ubuntu 操作系统上安装它。

先决条件

Ubuntu 终端sudo登录

Nginx 安装

安装过程非常简单,只需要一行命令。以下命令用于安装。
$ sudo apt-get install nginx
     
Software NGINX 1
安装后,我们可以在浏览器中输入localhost访问它,它会显示以下输出。
Software NGINX 2
好了,我们已经在 Ubuntu 操作系统上成功安装了它。

管理 Nginx 服务器

以下命令用于管理停止、启动等服务器任务

启动 Nginx

使用以下命令启动nginx服务器。
$ systemctl start nginx
     

停止 Nginx

使用以下命令停止 nginx 服务器。
$ systemctl stop nginx
     

重启Nginx

使用以下命令重启nginx服务器。
$ systemctl restart nginx
     

Nginx 状态

使用以下命令查看 Nginx 服务器状态
$ systemctl status nginx
     
Software NGINX 3

重新加载 Nginx

如果我们对服务器配置进行更改,只需重新加载 nginx 而不会断开连接。使用以下命令重新加载服务器。
$ systemctl reload nginx
     

在启动时禁用 Nginx

默认情况下,Nginx 在启动时启用并自动启动。如果我们想禁用它,请使用以下命令。
$ sudo systemctl disable nginx
     
Software NGINX 4

在启动时启用 Nginx

如果我们要启动Nginx 服务器在启动时自动运行,使用以下命令。
$ sudo systemctl enable nginx
     
软件 NGINX 5

额外信息

/var/www/html/ 是服务器根目录。
/etc/nginx/ 是配置目录。
/var/log/nginx/access.log 是包含所有请求记录的服务器日志文件。
/var/log/nginx/error.log 是包含错误记录的服务器错误日志文件。

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4