セキュリティヘッダーによるNginxの強化
NginxにHTTPセキュリティヘッダーを追加し、クリックジャッキング、MIMEスニッフィング、コンテンツインジェクション攻撃から防御します。
「セキュリティヘッダーによるNginxの強化」はCoddyKit上の無料API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)レッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはAPI Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)コースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Headers as a Defense Layer
Beyond TLS and authentication, modern browsers honor security headers that instruct them how to behave. Nginx can inject these on every response with the add_header directive.
Preventing MIME Sniffing
X-Content-Type-Options: nosniff stops browsers from guessing a resource's type, blocking attacks that disguise a script as an image.
add_header X-Content-Type-Options "nosniff" always;Blocking Clickjacking
X-Frame-Options controls whether your site can be embedded in a frame. Use DENY or SAMEORIGIN to prevent clickjacking.
add_header X-Frame-Options "SAMEORIGIN" always;Strict Transport Security
HSTS forces browsers to use HTTPS for future visits. Set a long max-age once HTTPS is stable everywhere.
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;Content Security Policy
A Content-Security-Policy restricts where scripts, styles, and other resources may load from, mitigating cross-site scripting.
add_header Content-Security-Policy "default-src 'self'" always;Controlling the Referrer
Referrer-Policy limits how much referrer information leaks to other sites when users click outbound links.
add_header Referrer-Policy "strict-origin-when-cross-origin" always;Why the always Flag
Without always, Nginx adds the header only on successful responses (2xx, 3xx). The always flag ensures the header is present on error responses too.
add_header X-Frame-Options "DENY" always;Hiding the Nginx Version
By default Nginx reveals its version in the Server header and error pages. Turn this off to give attackers less information.
server_tokens off;The add_header Inheritance Trap
If a location block has its own add_header, it replaces all inherited headers from the parent. Re-declare needed headers in nested blocks.
# headers in http/server are dropped here
location /api {
add_header X-Content-Type-Options "nosniff" always;
}Grouping Security Headers
Keep all security headers in one include file and pull it into each server block for consistency.
# security_headers.conf
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
# server block:
include /etc/nginx/security_headers.conf;Verifying Headers
Use curl to inspect the response headers and confirm each one is present, even on error responses.
curl -I https://example.comQuick Check
Which header tells the browser to refuse loading your site inside a frame on another domain?
Recap
You hardened Nginx with browser security headers:
nosniffblocks MIME confusionX-Frame-Optionsstops clickjacking- HSTS enforces HTTPS, CSP restricts resources
- Use
alwaysand bewareadd_headerinheritance server_tokens offhides the version
These complement TLS and authentication for defense in depth.
よくある質問
「セキュリティヘッダーによるNginxの強化」レッスンは無料ですか?
はい。「セキュリティヘッダーによるNginxの強化」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)コースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)コースには全4レッスンが含まれています。
「セキュリティヘッダーによるNginxの強化」で何を学びますか?
NginxにHTTPセキュリティヘッダーを追加し、クリックジャッキング、MIMEスニッフィング、コンテンツインジェクション攻撃から防御します。 ブラウザで直接実行するハンズオンコードでAPI Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)を演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)を始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのAPI Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)は初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「セキュリティヘッダーによるNginxの強化」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このAPI Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)レッスンでコードを書いて実行できますか?
はい。すべてのAPI Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)レッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- SSL/TLSによるNginxのセキュリティ強化
- HTTP/2とNginxの最適化
- Basic認証とアクセス制御
- セキュリティヘッダーによるNginxの強化