server { listen 80; server_name {{ domain_name }}{% if enable_www_redirect | default(false) %} 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 enable_www_redirect | default(false) %} www.{{ domain_name }}{% endif %}; root {{ web_root | default('/var/www/html') }}; index index.php index.html index.htm; # SSL Configuration ssl_certificate {{ ssl_cert_path | default('/etc/ssl/certs/nginx-selfsigned.crt') }}; ssl_certificate_key {{ ssl_cert_key_path | default('/etc/ssl/private/nginx-selfsigned.key') }}; # Modern SSL configuration (2026 best practices) ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305; ssl_prefer_server_ciphers off; ssl_session_timeout 1d; ssl_session_cache shared:SSL:10m; ssl_session_tickets off; # HSTS (HTTP Strict Transport Security) - 2 years for preload add_header Strict-Transport-Security "max-age=63072000; 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 (disabled for self-signed certificates) # ssl_stapling on; # ssl_stapling_verify on; # ssl_trusted_certificate {{ ssl_cert_path | default('/etc/ssl/certs/nginx-selfsigned.crt') }}; # 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) { # Admin area protection (rate limiting disabled for compatibility) 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; } }