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

Pemeriksaan Kesehatan dan Pemantauan Server

Terapkan pemeriksaan kesehatan untuk menghapus server backend yang tidak sehat secara otomatis dari kumpulan penyeimbang beban.

Pemeriksaan Kesehatan dan Pemantauan Server adalah pelajaran API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) gratis di CoddyKit. Ini adalah pelajaran 2 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

Keeping Servers Healthy

Imagine a busy restaurant with multiple chefs. If one chef gets sick, you don't want to send orders to them, right?

In load balancing, health checks do exactly that. They constantly monitor backend servers to ensure they are ready to handle requests.

Why Health Checks Matter

Without health checks, a load balancer might keep sending requests to a server that is down, overloaded, or unresponsive.

  • Bad User Experience: Users get errors instead of content.
  • Wasted Resources: The load balancer tries to connect to a dead end.
  • Cascading Failures: Overloads can spread if requests aren't redirected.

Nginx's Health Check Basics

Nginx provides built-in directives within its upstream block to perform passive health checks. These checks react to failed connection attempts or responses.

The two main directives are max_fails and fail_timeout.

`max_fails`: Failed Attempts

The max_fails directive sets the number of consecutive failed attempts after which Nginx considers a server "unhealthy".

  • Default: 1 (one failure marks it unhealthy).
  • `max_fails=0`: Disables health checks for that server.
  • A "failure" can be a connection error, timeout, or specific HTTP status codes (like 5xx) if configured.

`fail_timeout`: Recovery Time

Once a server is marked unhealthy, Nginx will stop sending requests to it for a duration specified by fail_timeout.

  • Default: 10s (10 seconds).
  • After this timeout, Nginx will tentatively send a request to the server to check if it has recovered.
  • This prevents hammering a down server.

Implementing Nginx Health Checks

Let's see how to configure max_fails and fail_timeout in an Nginx upstream block. Here, we define two backend servers.

http {
    upstream backend_servers {
        server 192.168.1.100:8080 max_fails=3 fail_timeout=15s;
        server 192.168.1.101:8080 max_fails=3 fail_timeout=15s;
    }

    server {
        listen 80;
        location / {
            proxy_pass http://backend_servers;
        }
    }
}

Nginx's Server Management

When a server hits its max_fails limit within the fail_timeout period, Nginx temporarily removes it from the load balancing pool.

  • Requests are then distributed among the remaining healthy servers.
  • After fail_timeout expires, Nginx tries sending a single request to the "unhealthy" server. If it succeeds, the server is marked healthy again.

Observing Server Health

While Nginx's basic health checks are passive, you can observe their effects in Nginx logs.

Error logs will show messages when a server is marked down or up. For more advanced, active monitoring and a dashboard, Nginx Plus offers dedicated features, but that's beyond basic Nginx.

Health Check Tips

Properly configuring health checks is key for reliable systems:

  • Tune Values: Adjust max_fails and fail_timeout based on your application's responsiveness and recovery time.
  • Backend Readiness: Ensure your backend applications have a dedicated health endpoint (e.g., /health) that reports true service readiness.
  • Combine with Monitoring: Use external monitoring tools to alert you when Nginx marks servers down.

Quick Check on Health Checks

You've configured an Nginx upstream server with max_fails=2 and fail_timeout=30s. If the server fails 3 consecutive requests, what happens next?

Health Check Recap

In this lesson, we learned about Nginx's essential health check directives:

  • max_fails: The number of failed attempts before a server is marked unhealthy.
  • fail_timeout: The period for which an unhealthy server is taken out of the load balancing pool.
  • These passive checks are crucial for maintaining backend reliability and improving user experience.

Pertanyaan yang Sering Diajukan

Apakah pelajaran “Pemeriksaan Kesehatan dan Pemantauan Server” gratis?

Ya — teks lengkap “Pemeriksaan Kesehatan dan Pemantauan Server” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), upgrade ke CoddyKit PRO. Kursus API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “Pemeriksaan Kesehatan dan Pemantauan Server”?

Terapkan pemeriksaan kesehatan untuk menghapus server backend yang tidak sehat secara otomatis dari kumpulan penyeimbang beban. Kamu berlatih API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)?

Tidak diperlukan pengalaman sebelumnya. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 2 dari 4.

Berapa lama pelajaran “Pemeriksaan Kesehatan dan Pemantauan Server” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) ini?

Ya. Setiap pelajaran API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. Algoritme Penyeimbangan Beban
  2. Pemeriksaan Kesehatan dan Pemantauan Server
  3. Sesi Lengket dan Persistensi Sesi
  4. Penyeimbangan Beban Berbobot & Server Cadangan
← Kembali ke API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)