0Pricing
API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) · 课时

Nginx 安装与设置

学习如何在各种操作系统上安装 Nginx,并完成初始配置步骤。

Nginx 安装与设置 是 CoddyKit 上的免费 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 课时。 这是第 1 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Get Ready to Install Nginx

Welcome! In this lesson, we'll get Nginx up and running on your system. Nginx (pronounced "engine-x") is a powerful web server and reverse proxy that's widely used for high-performance applications.

We'll cover installation on common operating systems and explore its initial setup.

Installing on Linux (APT)

For Debian or Ubuntu Linux, Nginx is readily available through the APT package manager. These commands will update your package list and install Nginx:

  • sudo apt update
  • sudo apt install nginx

The sudo command grants administrative privileges, necessary for system-wide changes.

sudo apt update
sudo apt install nginx

Check Nginx is Running

After installation, Nginx usually starts automatically. You can verify its status using systemctl, a command for controlling system services.

A successful output will show "active (running)". Try running this:

sudo systemctl status nginx

Managing Nginx Service

Knowing how to control the Nginx service is crucial. Here are the most common commands you'll use:

  • Start: sudo systemctl start nginx
  • Stop: sudo systemctl stop nginx
  • Restart: sudo systemctl restart nginx (stops and then starts)
  • Reload: sudo systemctl reload nginx (applies config changes without dropping connections)

Where to Find Configs

Nginx configurations live in specific directories. On Linux systems, the main configuration file is usually located at /etc/nginx/nginx.conf.

This main file often includes other configuration files from the /etc/nginx/sites-available/ directory. These are then symlinked (a type of shortcut) to /etc/nginx/sites-enabled/ to activate them.

Your First Nginx Page

Once Nginx is running, open your web browser and navigate to http://localhost/ or your server's IP address. You should see a default "Welcome to Nginx!" page.

This page confirms Nginx is serving content correctly from its default web root, which is typically /var/www/html.

How Nginx Listens

By default, Nginx listens for incoming web requests on port 80 (the standard HTTP port). This is configured in the nginx.conf file or included server blocks.

You can verify which ports Nginx is listening on using the ss command (Socket Statistics). Try running this example:

sudo ss -ltn | grep 80

Installation on macOS

For macOS users, Homebrew is the easiest way to install Nginx. Homebrew is a popular package manager for macOS.

First, ensure Homebrew is installed. Then, use the brew command to install Nginx and start its service:

brew install nginx
brew services start nginx

Installation Check

Let's test your understanding of basic Nginx service commands.

Recap: Nginx is Installed!

Great job! You've successfully learned how to install Nginx on both Linux and macOS, verify its status, and manage the service with basic commands.

We also touched upon where Nginx stores its configuration files and how to confirm it's serving the default page. In the next lesson, we'll dive into the basic Nginx configuration file structure!

常见问题解答

「Nginx 安装与设置」课时是免费的吗?

是的 — 「Nginx 安装与设置」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 课程的其余内容,请升级到 CoddyKit PRO。 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 课程共包含 4 节课。

「Nginx 安装与设置」这节课中我会学到什么?

学习如何在各种操作系统上安装 Nginx,并完成初始配置步骤。 你通过在浏览器中直接运行的动手代码来练习 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway),全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 需要有经验吗?

无需任何先前经验。CoddyKit 上的 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 1 节课,共 4 节。

「Nginx 安装与设置」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 课中编写并运行代码吗?

能。每节 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. Nginx 安装与设置
  2. Nginx 基础配置
  3. 使用 Nginx 提供静态内容
  4. Nginx 位置块与请求匹配
← 返回 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)