Nginx 七式防禦術:從零打造 DDoS 防護堡壘
Linux

Nginx 七式防禦術:從零打造 DDoS 防護堡壘

2026-02-23 · 15 分鐘 · Ray Lee (System Analyst)
Nginx DDoS 防禦概念圖:Nginx 伺服器以多層防護抵禦 DDoS 攻擊

前言:城門守衛的覺悟

天下伺服器之道,知架設者多,知防守者少。

曾幾何時,你的網站在深夜三點被不明流量灌爆,error log 像瀑布一樣往下滾,你只能抱著筆電對螢幕唸經。那一刻你才體悟到:架站只是入門,防守才是修行。

本文基於實戰經驗,分享如何用 Nginx 打造七層防禦工事,讓你的伺服器在 DDoS 洪流中屹立不搖。所有配置皆經過生產環境驗證,拿去直接用。

架構概覽:反向代理是第一道城牆

我們的架構很單純:Nginx 做反向代理,前面接網際網路,後面接多台應用伺服器。

Internet ──▶ Nginx (反向代理) ──▶ 後端服務群
                                    App-Server-A:8443  (ERP 系統)
                                    App-Server-B:443   (官網、API、CMS...)
                                    App-Server-C:8443  (預覽環境)

Nginx 就像城門守衛,所有流量必須經過它。這個位置天然適合做安全過濾。

第一式:隱匿身份 — 關閉版本資訊

駭客入侵的第一步是偵察。如果你的 Nginx 還在回應 header 裡大方地告訴全世界「我是 nginx/1.24.0」,那等於在城牆上掛了一面旗寫著「請針對此版本查漏洞」。

# nginx.conf
server_tokens off;

一行搞定。從此 HTTP response 不再暴露版本號,error page 也不會洩漏。

第二式:流量閘門 — Rate Limiting

這是對抗 DDoS 最核心的武器。原理很簡單:限制每個 IP 的請求速率。

全域定義(nginx.conf http 區塊)

# 請求頻率限制:每個 IP 每秒 10 次
limit_req_zone $binary_remote_addr zone=req_per_ip:10m rate=10r/s;

# 連線數限制:每個 IP 的同時連線數
limit_conn_zone $binary_remote_addr zone=conn_per_ip:10m;

套用到每個站點(server 區塊)

limit_req zone=req_per_ip burst=20 nodelay;
limit_conn conn_per_ip 50;

參數解讀:

  • rate=10r/s — 平均每秒 10 個請求(超過就排隊或丟棄)
  • burst=20 — 允許短暫爆發最多 20 個請求(應付正常用戶快速點擊)
  • nodelay — 爆發請求立即處理,不排隊等待
  • conn_per_ip 50 — 單一 IP 最多 50 條同時連線

進階技巧:某些站點(例如 ERP 系統)的正常使用就需要較高頻率,可以在該站的 server 區塊覆寫:

# ERP 站點:放寬 burst 限制
limit_req zone=req_per_ip burst=50 nodelay;

如何監控被限流的請求

被限流的請求會出現在 error log 中:

limiting requests, excess: 10.xxx by zone "req_per_ip"

統計被限流最多的 IP:

grep "limiting requests" /var/log/nginx/error.log \
  | awk '{print $NF}' | sort | uniq -c | sort -rn | head -20

第三式:鋼鐵頭盔 — Security Headers

HTTP Security Headers 是瀏覽器端的防護罩。我們把它抽成共用片段,所有站點 include 即可:

# /etc/nginx/snippets/security-headers.conf

add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
Header防護目標
X-Frame-Options防止 Clickjacking(禁止被其他網站 iframe 嵌入)
X-Content-Type-Options防止 MIME 類型嗅探攻擊
X-XSS-Protection啟用瀏覽器內建 XSS 過濾器
Referrer-Policy控制 Referrer 資訊洩漏範圍
HSTS強制瀏覽器使用 HTTPS(有效期一年)

第四式:空城計 — Default Server 丟棄未知請求

這招是我最愛的。當有人用 IP 直接連你的 443 port,或者用未知域名來敲門,Nginx 直接回 444(斷開連線,不回應任何內容):

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    server_name _;

    ssl_certificate /etc/nginx/ssl/dummy.crt;
    ssl_certificate_key /etc/nginx/ssl/dummy.key;

    return 444;
}

為什麼用 dummy 憑證?因為 SSL handshake 在 server_name 匹配之前就需要憑證。用自簽憑證完成握手,然後立刻斷開。

效果:掃描器和殭屍網路用 IP 掃你的 port,只會得到一個無聲的斷線。不給任何資訊,不浪費任何資源。

第五式:金鐘罩 — SSL/TLS 加固

使用 Let’s Encrypt 免費憑證,搭配嚴格的協定設定:

  • 僅允許 TLS 1.2 和 1.3(淘汰 SSLv3、TLS 1.0、1.1)
  • 使用 Mozilla 推薦的 cipher suites
  • 啟用 DH 參數強化金鑰交換
  • 啟用 HTTP/2 提升效能
server {
    listen 443 ssl;
    http2 on;

    ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    # ... 其他配置
}

第六式:防慢攻 — Anti-Slowloris

Slowloris 是一種低頻攻擊:攻擊者開啟大量連線,但每條連線都極慢地傳送 header,佔住伺服器的 worker。對策是設定嚴格的 timeout 和 buffer 限制:

# nginx.conf — 全域連線限制

client_body_timeout 10s;       # 讀取 body 超時
client_header_timeout 10s;     # 讀取 header 超時
keepalive_timeout 15s;         # keep-alive 超時
client_body_buffer_size 16k;   # body 緩衝區大小
client_header_buffer_size 1k;  # header 緩衝區大小
large_client_header_buffers 4 8k;
# 每個站點的 proxy timeout

proxy_connect_timeout 30;
proxy_send_timeout 120;
proxy_read_timeout 120;
send_timeout 30;

邏輯:如果你 10 秒內送不完 header,那你八成不是正常用戶。掰掰。

第七式:封印術 — 隱藏檔案保護

最後一道防線,阻止任何人存取 hidden files:

location ~ /\. {
    deny all;
}

這可以防止 .git.env.htaccess 等敏感檔案被存取。你不會想讓全世界看到你的 .env 裡面寫了什麼。

完整站點配置模板

把以上七式合體,一個完整的站點配置長這樣:

server {
    listen 80;
    listen [::]:80;
    server_name your-domain.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    http2 on;
    server_name your-domain.com;

    ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    client_max_body_size 100M;
    proxy_connect_timeout 30;
    proxy_send_timeout 120;
    proxy_read_timeout 120;
    send_timeout 30;

    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;

    include /etc/nginx/snippets/security-headers.conf;
    limit_req zone=req_per_ip burst=20 nodelay;
    limit_conn conn_per_ip 50;

    location ~ /\. {
        deny all;
    }

    location / {
        proxy_pass https://backend-server:port;
    }
}

雷公李曰

雷公李曰:「余觀天下之 DDoS,其勢如洪水,來者不拒則城必陷。然 Nginx 七式者,隱版本以匿形,限流量以御洪,加頭盔以護體,設空城以拒客,鍛金鐘以固壁,防慢攻以斷詐,封隱檔以絕患。七式合一,雖千萬請求吾往矣。」

記住:沒有絕對安全的系統,只有持續進化的防禦。定期檢查 log、更新配置、關注安全公告,才是長久之道。

願你的伺服器永遠不需要在凌晨三點叫醒你。🛡️

English Version

Prologue: The Gatekeeper’s Awakening

In the world of servers, many know how to build — few know how to defend.

We’ve all been there: it’s 3 AM, mysterious traffic is hammering your server, the error log scrolls like a waterfall, and you’re clutching your laptop, whispering prayers to the ops gods. That’s when it hits you: setting up a server is just the beginning — defending it is the real craft.

This article shares battle-tested techniques for building seven layers of defense with Nginx, keeping your server standing tall against DDoS floods. All configurations are production-proven. Copy, paste, sleep soundly.

Architecture Overview: Reverse Proxy as the First Wall

The architecture is straightforward: Nginx as a reverse proxy, facing the internet on one side and backend application servers on the other.

Internet ──▶ Nginx (Reverse Proxy) ──▶ Backend Services
                                        App-Server-A:8443  (ERP System)
                                        App-Server-B:443   (Website, API, CMS...)
                                        App-Server-C:8443  (Preview Env)

Nginx acts as the gatekeeper — all traffic must pass through it. This position is naturally suited for security filtering.

Move 1: Hide Your Identity — Disable Version Info

The first step of any attack is reconnaissance. If your Nginx is cheerfully announcing “I’m nginx/1.24.0” in every response header, you might as well hang a banner on your wall saying “Please look up vulnerabilities for this version.”

# nginx.conf
server_tokens off;

One line. Done. No more version leaks in HTTP responses or error pages.

Move 2: The Flood Gate — Rate Limiting

This is the core weapon against DDoS. The concept is simple: limit the request rate per IP address.

Global Definition (nginx.conf http block)

# Request rate limit: 10 requests per second per IP
limit_req_zone $binary_remote_addr zone=req_per_ip:10m rate=10r/s;

# Connection limit: concurrent connections per IP
limit_conn_zone $binary_remote_addr zone=conn_per_ip:10m;

Apply to Each Site (server block)

limit_req zone=req_per_ip burst=20 nodelay;
limit_conn conn_per_ip 50;

Parameter breakdown:

  • rate=10r/s — Average 10 requests per second (excess gets queued or dropped)
  • burst=20 — Allows short bursts of up to 20 requests (for normal rapid clicking)
  • nodelay — Burst requests are served immediately, no queuing
  • conn_per_ip 50 — Maximum 50 simultaneous connections per IP

Pro tip: Some sites (like ERP systems) legitimately need higher rates. Override in that site’s server block:

# ERP site: more lenient burst limit
limit_req zone=req_per_ip burst=50 nodelay;

Monitoring Rate-Limited Requests

Rate-limited requests appear in the error log:

limiting requests, excess: 10.xxx by zone "req_per_ip"

Count the most rate-limited IPs:

grep "limiting requests" /var/log/nginx/error.log \
  | awk '{print $NF}' | sort | uniq -c | sort -rn | head -20

Move 3: The Steel Helmet — Security Headers

HTTP Security Headers act as browser-side shields. We extract them into a shared snippet for all sites to include:

# /etc/nginx/snippets/security-headers.conf

add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
HeaderProtection Target
X-Frame-OptionsPrevents clickjacking (blocks iframe embedding from other origins)
X-Content-Type-OptionsPrevents MIME type sniffing attacks
X-XSS-ProtectionEnables browser’s built-in XSS filter
Referrer-PolicyControls referrer information leakage scope
HSTSForces browser to use HTTPS (valid for 1 year)

Move 4: The Empty Fort — Drop Unknown Requests

This is my personal favorite. When someone connects to your port 443 with a raw IP or unknown domain, Nginx responds with 444 — which means “drop connection, send nothing”:

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    server_name _;

    ssl_certificate /etc/nginx/ssl/dummy.crt;
    ssl_certificate_key /etc/nginx/ssl/dummy.key;

    return 444;
}

Why the dummy certificate? Because SSL handshake happens before server_name matching — you need a certificate to complete the handshake, then immediately disconnect.

Effect: Scanners and botnets probing your ports with raw IPs get nothing but silence. Zero information leaked, zero resources wasted.

Move 5: The Iron Shield — SSL/TLS Hardening

Using free Let’s Encrypt certificates with strict protocol settings:

  • TLS 1.2 and 1.3 only (goodbye SSLv3, TLS 1.0, 1.1)
  • Mozilla-recommended cipher suites
  • DH parameters for stronger key exchange
  • HTTP/2 enabled for performance
server {
    listen 443 ssl;
    http2 on;

    ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    # ... other configurations
}

Move 6: Anti-Slowloris — Timeout the Cheaters

Slowloris is a low-bandwidth attack: the attacker opens many connections but sends headers extremely slowly, tying up server workers. The countermeasure is strict timeout and buffer limits:

# nginx.conf — global connection limits

client_body_timeout 10s;       # Body read timeout
client_header_timeout 10s;     # Header read timeout
keepalive_timeout 15s;         # Keep-alive timeout
client_body_buffer_size 16k;   # Body buffer size
client_header_buffer_size 1k;  # Header buffer size
large_client_header_buffers 4 8k;
# Per-site proxy timeouts

proxy_connect_timeout 30;
proxy_send_timeout 120;
proxy_read_timeout 120;
send_timeout 30;

Logic: If you can’t finish sending your headers in 10 seconds, you’re probably not a real user. Bye.

Move 7: The Seal — Hidden File Protection

The final line of defense — block access to all hidden files:

location ~ /\. {
    deny all;
}

This prevents access to sensitive files like .git, .env, and .htaccess. Trust me, you don’t want the whole world reading your .env.

Complete Site Configuration Template

Combining all seven moves, a complete site configuration looks like this:

server {
    listen 80;
    listen [::]:80;
    server_name your-domain.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    http2 on;
    server_name your-domain.com;

    ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    client_max_body_size 100M;
    proxy_connect_timeout 30;
    proxy_send_timeout 120;
    proxy_read_timeout 120;
    send_timeout 30;

    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;

    include /etc/nginx/snippets/security-headers.conf;
    limit_req zone=req_per_ip burst=20 nodelay;
    limit_conn conn_per_ip 50;

    location ~ /\. {
        deny all;
    }

    location / {
        proxy_pass https://backend-server:port;
    }
}

Ray Lee’s Verdict

Ray Lee writes: “I have observed the DDoS attacks of this world — they come like floods, and those who accept all comers shall surely fall. But the Seven Moves of Nginx — hiding version to conceal form, limiting rate to stem the flood, adding headers to shield the body, deploying the empty fort to refuse intruders, forging the iron shield to harden walls, timing out cheaters to sever deceit, sealing hidden files to eliminate vulnerabilities — when these seven become one, though ten million requests come, I shall stand.”

Remember: there is no absolutely secure system — only continuously evolving defense. Regularly check your logs, update your configurations, and stay informed on security advisories. That is the way of lasting protection.

May your server never wake you at 3 AM.

日本語版

序章:門番の覚悟

天下のサーバー道において、構築を知る者は多いが、守備を知る者は少ない。

深夜3時、正体不明のトラフィックにサーバーが叩かれ、error log が滝のようにスクロールし、ノートPCを抱えて画面に向かってお経を唱える——そんな経験、ありませんか?あの瞬間こそ悟るのです。サーバーを立てるのは入門に過ぎない。守ることこそが修行である。

本記事では、実戦経験に基づき、Nginx で七重の防御陣を構築する方法を共有します。すべての設定は本番環境で検証済み。コピペしてぐっすり眠ってください。

アーキテクチャ概要:リバースプロキシは最初の城壁

アーキテクチャはシンプルです。Nginx がリバースプロキシとして、インターネット側と複数のバックエンドサーバーの間に立ちます。

Internet ──▶ Nginx (リバースプロキシ) ──▶ バックエンドサービス群
                                            App-Server-A:8443  (ERPシステム)
                                            App-Server-B:443   (公式サイト、API、CMS...)
                                            App-Server-C:8443  (プレビュー環境)

Nginx は門番のような存在で、すべてのトラフィックはここを通過しなければなりません。セキュリティフィルタリングに最適なポジションです。

第一の型:隠形 — バージョン情報の非表示

ハッカーの最初のステップは偵察です。Nginx がレスポンスヘッダーで「nginx/1.24.0です」と親切に自己紹介しているなら、城壁に「このバージョンの脆弱性を調べてください」という旗を掲げているようなものです。

# nginx.conf
server_tokens off;

一行で完了。HTTP レスポンスやエラーページからバージョン番号が消えます。

第二の型:水門 — レート制限

DDoS 対策の最も核心的な武器です。原理はシンプル:IP アドレスごとのリクエスト速度を制限する。

グローバル定義(nginx.conf http ブロック)

# リクエスト頻度制限:IP ごとに毎秒10リクエスト
limit_req_zone $binary_remote_addr zone=req_per_ip:10m rate=10r/s;

# 接続数制限:IP ごとの同時接続数
limit_conn_zone $binary_remote_addr zone=conn_per_ip:10m;

各サイトに適用(server ブロック)

limit_req zone=req_per_ip burst=20 nodelay;
limit_conn conn_per_ip 50;

パラメータ解説:

  • rate=10r/s — 平均毎秒10リクエスト(超過分はキュー待ちまたは破棄)
  • burst=20 — 最大20リクエストの短期バースト許可(通常ユーザーの連続クリック対応)
  • nodelay — バーストリクエストを即座に処理(キュー待ちなし)
  • conn_per_ip 50 — 単一 IP の最大同時接続数50

上級テクニック:一部のサイト(ERP システムなど)は通常利用でも高い頻度が必要です。該当サイトの server ブロックで上書きできます:

# ERP サイト:burst 制限を緩和
limit_req zone=req_per_ip burst=50 nodelay;

レート制限されたリクエストの監視

制限されたリクエストは error log に記録されます:

limiting requests, excess: 10.xxx by zone "req_per_ip"

制限された IP の統計:

grep "limiting requests" /var/log/nginx/error.log \
  | awk '{print $NF}' | sort | uniq -c | sort -rn | head -20

第三の型:鋼鉄の兜 — セキュリティヘッダー

HTTP セキュリティヘッダーはブラウザ側の防護盾です。共通スニペットとして抽出し、全サイトで include するだけ:

# /etc/nginx/snippets/security-headers.conf

add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
ヘッダー防護対象
X-Frame-Optionsクリックジャッキング防止(他サイトからの iframe 埋め込みをブロック)
X-Content-Type-OptionsMIME タイプスニッフィング攻撃の防止
X-XSS-Protectionブラウザ内蔵 XSS フィルターの有効化
Referrer-Policyリファラー情報の漏洩範囲を制御
HSTSブラウザに HTTPS 使用を強制(有効期間1年)

第四の型:空城の計 — 不明リクエストの破棄

これが個人的に最も気に入っている技です。誰かが IP アドレスで直接443ポートに接続したり、未知のドメインでアクセスした場合、Nginx は 444 を返します(接続を切断し、何も応答しない):

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    server_name _;

    ssl_certificate /etc/nginx/ssl/dummy.crt;
    ssl_certificate_key /etc/nginx/ssl/dummy.key;

    return 444;
}

なぜダミー証明書を使うのか?SSL ハンドシェイクは server_name マッチング前に証明書が必要だからです。自己署名証明書でハンドシェイクを完了させ、即座に切断します。

効果:スキャナーやボットネットが IP でポートスキャンしても、無言の切断しか得られません。情報漏洩ゼロ、リソース浪費ゼロ。

第五の型:金鐘罩 — SSL/TLS の強化

Let’s Encrypt の無料証明書を使用し、厳格なプロトコル設定を適用:

  • TLS 1.2 と 1.3 のみ許可(SSLv3、TLS 1.0、1.1 は廃止)
  • Mozilla 推奨の暗号スイートを使用
  • DH パラメータで鍵交換を強化
  • HTTP/2 有効化でパフォーマンス向上
server {
    listen 443 ssl;
    http2 on;

    ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    # ... その他の設定
}

第六の型:対スローロリス — チーターをタイムアウト

Slowloris は低帯域攻撃の一種です。攻撃者は大量の接続を開きますが、各接続で極めてゆっくりとヘッダーを送信し、サーバーのワーカーを占有します。対策は厳格なタイムアウトとバッファ制限です:

# nginx.conf — グローバル接続制限

client_body_timeout 10s;       # ボディ読み取りタイムアウト
client_header_timeout 10s;     # ヘッダー読み取りタイムアウト
keepalive_timeout 15s;         # キープアライブタイムアウト
client_body_buffer_size 16k;   # ボディバッファサイズ
client_header_buffer_size 1k;  # ヘッダーバッファサイズ
large_client_header_buffers 4 8k;
# 各サイトのプロキシタイムアウト

proxy_connect_timeout 30;
proxy_send_timeout 120;
proxy_read_timeout 120;
send_timeout 30;

ロジック:10秒以内にヘッダーを送り終えられないなら、おそらく正常なユーザーではありません。さようなら。

第七の型:封印術 — 隠しファイル保護

最後の防衛線——隠しファイルへのアクセスをすべてブロック:

location ~ /\. {
    deny all;
}

これにより、.git.env.htaccess などの機密ファイルへのアクセスが防止されます。.env の中身を世界中に公開したくはないでしょう。

完全なサイト設定テンプレート

七つの型を合体させた、完全なサイト設定は以下の通りです:

server {
    listen 80;
    listen [::]:80;
    server_name your-domain.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    http2 on;
    server_name your-domain.com;

    ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    client_max_body_size 100M;
    proxy_connect_timeout 30;
    proxy_send_timeout 120;
    proxy_read_timeout 120;
    send_timeout 30;

    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;

    include /etc/nginx/snippets/security-headers.conf;
    limit_req zone=req_per_ip burst=20 nodelay;
    limit_conn conn_per_ip 50;

    location ~ /\. {
        deny all;
    }

    location / {
        proxy_pass https://backend-server:port;
    }
}

雷公李曰

雷公李曰く:「余、天下の DDoS を観るに、その勢い洪水の如し。来る者を拒まざれば城は必ず陥つ。然れども Nginx 七つの型は——バージョンを隠して形を匿し、流量を制して洪を御し、ヘッダーを加えて体を護り、空城を設けて客を拒み、金鐘を鍛えて壁を固め、スローを防ぎて詐を断ち、隠しファイルを封じて患いを絶つ。七つの型が一つとなれば、千万のリクエストが来ようとも、我は立つ。」

忘れないでください:絶対に安全なシステムは存在しません。あるのは、進化し続ける防御のみです。定期的にログを確認し、設定を更新し、セキュリティ情報に注意を払うこと。それこそが長く続く道です。

あなたのサーバーが、深夜3時にあなたを起こすことがありませんように。

Ray Lee (System Analyst)
作者 Ray Lee (System Analyst)

iDempeire ERP Contributor, 經濟部中小企業處財務管理顧問 李寶瑞