server { listen 80; server_name {{ domain_name }}{% if www_redirect %} www.{{ domain_name }}{% endif %}; # Redirect HTTP to HTTPS return 301 https://$server_name$request_uri; } server { listen 443 ssl http2; server_name {{ domain_name }}{% if www_redirect %} www.{{ domain_name }}{% endif %}; root {{ wordpress_path }}; index index.php index.html index.htm; # SSL Configuration ssl_certificate {{ ssl_certificate_path }}; ssl_certificate_key {{ ssl_certificate_key_path }}; # Modern SSL configuration ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384; ssl_prefer_server_ciphers off; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; # HSTS (HTTP Strict Transport Security) add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always; # Security headers add_header X-Frame-Options DENY 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; # OCSP Stapling ssl_stapling on; ssl_stapling_verify on; ssl_trusted_certificate {{ ssl_certificate_path }}; resolver 8.8.8.8 8.8.4.4 valid=300s; resolver_timeout 5s; # WordPress specific rules location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:{{ php_fpm_socket }}; fastcgi_param HTTPS on; } location ~ /\.ht { deny all; } # WordPress uploads location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ { expires 1y; add_header Cache-Control "public, immutable"; } # WordPress security location ~ ^/(wp-admin|wp-login\.php) { # Rate limiting for admin limit_req zone=admin burst=5 nodelay; include snippets/fastcgi-php.conf; fastcgi_pass unix:{{ php_fpm_socket }}; fastcgi_param HTTPS on; } # Deny access to sensitive files location ~* ^/(wp-config\.php|wp-config-sample\.php|readme\.html|license\.txt)$ { deny all; } # Deny access to any files with a .php extension in the uploads directory location ~* /(?:uploads|files)/.*\.php$ { deny all; } }