server { listen 80; server_name _; root /var/www/html/public; index index.php index.html; # Security headers add_header X-Frame-Options "SAMEORIGIN" always; add_header X-XSS-Protection "1; mode=block" always; add_header X-Content-Type-Options "nosniff" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; add_header Content-Security-Policy "default-src 'self' http: https: ws: wss: data: blob: 'unsafe-inline'; frame-ancestors 'self';" always; # 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/rss+xml application/atom+xml image/svg+xml; # Max upload size (adjust as needed) client_max_body_size 64M; # Health check endpoint location /health { access_log off; return 200 "OK\n"; add_header Content-Type text/plain; } # Handle Laravel routing location / { try_files $uri $uri/ /index.php?$query_string; } # Pass PHP requests to PHP-FPM location ~ \.php$ { fastcgi_pass app:9000; fastcgi_index index.php; fastcgi_buffers 16 16k; fastcgi_buffer_size 32k; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; # AWS ALB / Reverse proxy headers fastcgi_param HTTP_X_FORWARDED_FOR $http_x_forwarded_for; fastcgi_param HTTP_X_FORWARDED_PROTO $http_x_forwarded_proto; fastcgi_param HTTP_X_FORWARDED_PORT $http_x_forwarded_port; # Timeouts for long-running requests fastcgi_read_timeout 300; fastcgi_connect_timeout 60; fastcgi_send_timeout 300; } # Static asset caching location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml|woff|woff2|ttf|svg|webp)$ { expires 30d; access_log off; add_header Cache-Control "public, immutable"; log_not_found off; } # Deny access to hidden files location ~ /\. { deny all; access_log off; log_not_found off; } # Deny access to sensitive files location ~ \.(env|log|sql|sh|bak)$ { deny all; return 404; } error_log /var/log/nginx/error.log warn; access_log /var/log/nginx/access.log combined; }