0Pricing
API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) · 강의

업스트림 서버 및 부하 분산

여러 백엔드 서버를 관리하고 들어오는 요청을 분산하도록 Nginx 업스트림 블록을 설정해 보세요.

업스트림 서버 및 부하 분산은(는) CoddyKit의 무료 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Scaling Your Applications

As your web application grows, a single server might not be enough to handle all incoming requests. This can lead to slow response times or even crashes.

To prevent this, we use multiple backend servers to share the load. This improves both performance and reliability.

Introducing Upstream Servers

Nginx can act as a reverse proxy, distributing requests to a group of backend servers. These backend servers are often called upstream servers.

  • Scalability: Handle more traffic by adding more servers.
  • High Availability: If one server fails, others can still respond.
  • Load Balancing: Distribute requests efficiently among servers.

The `upstream` Block

In Nginx, you define a group of backend servers using the upstream block. This block gives a name to your group of servers, which you can then reference in your location blocks.

Think of it as a named pool of resources that Nginx can forward requests to.

Basic Upstream Configuration

Here's how to define a simple upstream block named my_backends with two servers. Each server directive specifies the address (IP or hostname) and port of a backend server.

upstream my_backends {
  server 192.168.1.100:8080;
  server 192.168.1.101:8080;
}

Connecting Upstream to `location`

Once an upstream block is defined, you can use it within a location block in your Nginx server configuration. The proxy_pass directive tells Nginx to forward requests to the specified upstream group.

Notice we use http://my_backends to reference our defined group.

http {
  upstream my_backends {
    server 192.168.1.100:8080;
    server 192.168.1.101:8080;
  }

  server {
    listen 80;
    location /app {
      proxy_pass http://my_backends;
    }
  }
}

Default Load Balancing: Round Robin

By default, Nginx uses the Round Robin load balancing method. This means requests are distributed to upstream servers in a rotating, sequential manner.

  • Request 1 goes to Server A.
  • Request 2 goes to Server B.
  • Request 3 goes to Server A.
  • ...and so on.

It's simple and effective for evenly distributed loads.

Customizing Load with `weight`

What if some servers are more powerful or should handle more traffic? You can use the weight parameter in the server directive to assign different priorities.

A server with a higher weight will receive a proportionally larger share of requests.

`weight` Example in Nginx

In this example, server 1 has a weight of 3, and server 2 has a weight of 1. This means server 1 will receive 3 times as many requests as server 2.

Out of every 4 requests, 3 will go to server 1 and 1 to server 2.

upstream my_backends {
  server 192.168.1.100:8080 weight=3;
  server 192.168.1.101:8080 weight=1;
}

Other Server Directives

Beyond weight, other directives can fine-tune server behavior:

  • max_fails=N: Number of failed attempts before Nginx considers the server unavailable.
  • fail_timeout=Xs: Time for which the server is considered unavailable after max_fails attempts.
  • backup: Marks a server as a backup, used only when all primary servers are down.
  • down: Marks a server as permanently unavailable.

These help Nginx manage server health automatically.

Quick Check: Upstream & Load Balancing

Consider the following Nginx configuration snippet:

upstream api_servers {
  server backend1.example.com:8080 weight=2;
  server backend2.example.com:8080;
}

server {
  listen 80;
  location /api {
    proxy_pass http://api_servers;
  }
}

If 9 requests arrive at the /api endpoint, how many requests will be sent to backend1.example.com:8080?

Recap & Next Steps

You've learned how Nginx uses upstream blocks to group multiple backend servers, enabling load balancing and improving application resilience.

  • upstream block: Defines a named group of servers.
  • proxy_pass: Connects a location to an upstream group.
  • Round Robin: Nginx's default load balancing method.
  • weight directive: Customizes request distribution among servers.

Next, we'll explore how Nginx can improve performance with proxy buffering and caching!

자주 묻는 질문

“업스트림 서버 및 부하 분산” 강의는 무료인가요?

네 — “업스트림 서버 및 부하 분산” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 강의 전체를 잠금 해제할 수 있습니다. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 강의에는 총 4개의 강의가 포함되어 있습니다.

“업스트림 서버 및 부하 분산”에서 뭘 배우나요?

여러 백엔드 서버를 관리하고 들어오는 요청을 분산하도록 Nginx 업스트림 블록을 설정해 보세요. 브라우저에서 직접 실행하는 실습 코드로 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.

“업스트림 서버 및 부하 분산” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 간단한 역방향 프록시 설정
  2. 업스트림 서버 및 부하 분산
  3. 프록시 버퍼링 및 캐싱
  4. 헤더 전달 및 클라이언트 IP
← API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)(으)로 돌아가기