Nginx Secure Configuration
安全なWebサーバー設定・構成コード参照ガイド
Webサーバー / CDN
Nginx Secure Configuration
標準設定ファイル種別
Nginx Server Block Configuration
セキュリティ監査の適用範囲
安全なNginxサーバーブロックの構成、リダイレクトループの防止、HTTPS強制転送、HSTSヘッダーの有効化、およびコンテンツセキュリティポリシー(CSP)の設定方法。
Webサーバー堅牢化の基本原則
Webサーバー層(Nginx, Apache)やエッジCDN(Cloudflare)での適切なセキュリティ設定の適用は、通信の盗聴や改ざん、情報漏洩を防ぐための最も重要かつ基本的な対策です。正しいリダイレクトの設定により平文通信を排除し、セキュリティヘッダーの付与により各種インジェクション攻撃を防止します。
設定コードの適用手順
HTTPS Enforced Redirection (301)
Redirect all unencrypted HTTP traffic to HTTPS securely.
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}Strict Security Headers Configuration
Protect visitors against XSS, clickjacking, and mime-type sniffing.
# Add security headers globally
add_header X-Frame-Options "DENY" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;