如何在Ubuntu 18.04上安装Nginx

本教程详细介绍了如何在Ubuntu 18.04服务器上安装Nginx,包括更新包索引、安装Nginx、调整防火墙以允许HTTP访问、检查Web服务器运行状况、管理Nginx进程,以及设置服务器块。通过这些步骤,您可以确保Nginx正确配置并准备处理Web流量。
摘要由CSDN通过智能技术生成

介绍 (Introduction)

Nginx is one of the most popular web servers in the world and is responsible for hosting some of the largest and highest-traffic sites on the internet. It is more resource-friendly than Apache in most cases and can be used as a web server or reverse proxy.

Nginx是世界上最受欢迎的Web服务器之一,负责托管Internet上一些最大和流量最高的站点。 在大多数情况下,它比Apache更对资源友好,并且可以用作Web服务器或反向代理。

In this guide, we’ll discuss how to install Nginx on your Ubuntu 18.04 server.

在本指南中,我们将讨论如何在Ubuntu 18.04服务器上安装Nginx。

先决条件 (Prerequisites)

Before you begin this guide, you should have a regular, non-root user with sudo privileges configured on your server. You can learn how to configure a regular user account by following our initial server setup guide for Ubuntu 18.04.

在开始本指南之前,您应该在服务器上配置具有sudo特权的常规非root用户。 您可以按照我们针对Ubuntu 18.04的初始服务器设置指南,了解如何配置常规用户帐户。

When you have an account available, log in as your non-root user to begin.

如果您有可用的帐户,请以非root用户身份登录以开始。

步骤1 –安装Nginx (Step 1 – Installing Nginx)

Because Nginx is available in Ubuntu’s default repositories, it is possible to install it from these repositories using the apt packaging system.

由于Nginx在Ubuntu的默认存储库中可用,因此可以使用apt打包系统从这些存储库中安装Nginx。

Since this is our first interaction with the apt packaging system in this session, we will update our local package index so that we have access to the most recent package listings. Afterwards, we can install nginx:

由于这是我们在此会话中与apt打包系统的第一次交互,因此我们将更新本地包索引,以便我们可以访问最新的包清单。 之后,我们可以安装nginx

  • sudo apt update

    sudo apt更新
  • sudo apt install nginx

    sudo apt安装nginx

After accepting the procedure, apt will install Nginx and any required dependencies to your server.

接受该过程后, apt将把Nginx和所有必需的依赖项安装到您的服务器。

步骤2 –调整防火墙 (Step 2 – Adjusting the Firewall)

Before testing Nginx, the firewall software needs to be adjusted to allow access to the service. Nginx registers itself as a service with ufw upon installation, making it straightforward to allow Nginx access.

在测试Nginx之前,需要调整防火墙软件以允许访问该服务。 Nginx在安装时将自己注册为ufw服务,这使得直接允许Nginx访问成为可能。

List the application configurations that ufw knows how to work with by typing:

键入以下内容,列出ufw知道如何使用的应用程序配置:

  • sudo ufw app list

    sudo ufw应用程序列表

You should get a listing of the application profiles:

您应该获得应用程序配置文件的列表:


   
   
   
Output
Available applications: Nginx Full Nginx HTTP Nginx HTTPS OpenSSH

As you can see, there are three profiles available for Nginx:

如您所见,Nginx提供了三个配置文件:

  • Nginx Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)

    Nginx Full :此配置文件同时打开端口80(正常,未加密的网络流量)和端口443(TLS / SSL加密的流量)

  • Nginx HTTP: This profile opens only port 80 (normal, unencrypted web traffic)

    Nginx HTTP :此配置文件仅打开端口80(正常,未加密的网络流量)

  • Nginx HTTPS: This profile opens only port 443 (TLS/SSL encrypted traffic)

    Nginx HTTPS :此配置文件仅打开端口443(TLS / SSL加密流量)

It is recommended that you enable the most restrictive profile that will still allow the traffic you’ve configured. Since we haven’t configured SSL for our server yet in this guide, we will only need to allow traffic on port 80.

建议您启用限制性最强的配置文件,该配置文件仍将允许您配置的流量。 由于在本指南中我们尚未为服务器配置SSL,因此我们只需要允许端口80上的流量。

You can enable this by typing:

您可以通过键入以下内容启用此功能:

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值