server { server_name eveindy.claytonia.net; root /home/eveindy; index index.php index.html index.htm; # Compression gzip on; gzip_vary on; gzip_min_length 1000; gzip_comp_level 6; gzip_types text/plain text/css application/javascript image/x-icon application/json text/xml application/xml application/xml+rss text/javascript; # Logs access_log /var/log/nginx/eveindy_access.log; error_log /var/log/nginx/eveindy_error.log; # Error pages error_page 404 /404.php; # Security headers add_header X-Content-Type-Options "nosniff" always; add_header X-XSS-Protection "1; mode=block" always; add_header X-Frame-Options "SAMEORIGIN" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; # Allow visits.json (must be before the json block) location = /visits.json { allow all; } # Static files with caching location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg)$ { expires 1y; add_header Cache-Control "public, no-transform"; access_log off; try_files $uri =404; } # PHP handling location ~ \.php$ { try_files $uri =404; include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; # Preload critical assets add_header Link "; rel=preload; as=style" always; add_header Link "; rel=preload; as=image" always; } # Block sensitive files location ~ \.(json|txt|log|cache)$ { deny all; access_log off; } # Protect dot files location ~ /\. { deny all; access_log off; } # Default location location / { try_files $uri $uri/ $uri.php =404; } # Remove www if ($host ~* ^www\.(.*)) { return 301 https://$1$request_uri; } # Remove trailing slashes rewrite ^/(.*)/$ /$1 permanent; # SSL Configuration listen 443 ssl; ssl_certificate /path/to/cert.pem; ssl_certificate_key /path/to/key.pem; include /etc/letsencrypt/options-ssl-nginx.conf; ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # SSL optimizations ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; ssl_prefer_server_ciphers on; } # HTTP to HTTPS redirect server { listen 80; server_name your-domain.com; return 301 https://$server_name$request_uri; }