server { listen 80; listen [::]:80; server_name localhost; root /usr/share/nginx/html/public; add_header X-Frame-Options "SAMEORIGIN"; add_header X-Content-Type-Options "nosniff"; add_header X-XSS-Protection "1; mode=block"; index index.php index.html; charset utf-8; # Logging access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; # Security headers add_header Referrer-Policy "no-referrer-when-downgrade"; add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline' 'unsafe-eval';"; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always; add_header Permissions-Policy "geolocation=(), midi=(), notifications=(), push=(), sync-xhr=(), microphone=(), camera=(), magnetometer=(), gyroscope=(), speaker=(), vibrate=(), fullscreen=(), payment=(), interest-cohort=()"; # Handle all requests through index.php location / { try_files $uri $uri/ /index.php?$query_string; } # Handle PHP files location ~ \.php$ { fastcgi_pass [PHP_FPM_SERVICE]:9000; # Replace with your PHP-FPM service name fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; include fastcgi_params; fastcgi_read_timeout 300; } # Deny access to hidden files location ~ /\.(?!well-known).* { deny all; } # Deny access to storage and bootstrap/cache location ~ ^/(storage|bootstrap/cache) { deny all; } # Enable gzip compression gzip on; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml; gzip_min_length 1000; # Cache control for assets location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ { expires 1y; add_header Cache-Control "public, no-transform"; access_log off; log_not_found off; } # Disable access to .env file location ~ /\.env { deny all; } # Disable access to .git directory location ~ /\.git { deny all; } # Disable access to composer files location ~ /(composer\.json|composer\.lock|package\.json|package-lock\.json) { deny all; } # Error pages error_page 404 /index.php; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }