server { listen 80; server_name your-domain.com www.your-domain.com; root /var/www/bikeservice/backend/public; index index.php index.html index.htm; # 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 "no-referrer-when-downgrade" always; add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always; # Gzip compression gzip on; gzip_vary on; gzip_min_length 1024; gzip_proxied any; gzip_comp_level 6; gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss application/atom+xml image/svg+xml; # Handle Laravel routes location / { try_files $uri $uri/ /index.php?$query_string; } # Handle PHP files location ~ \.php$ { fastcgi_pass unix:/var/run/php/php8.2-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; # FastCGI optimizations fastcgi_buffer_size 128k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k; fastcgi_read_timeout 300; } # Deny access to hidden files location ~ /\.(?!well-known).* { deny all; } # Deny access to sensitive files location ~* \.(env|log|sql|md|txt|yml|yaml|ini)$ { deny all; } # Cache static assets location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { expires 1y; add_header Cache-Control "public, immutable"; add_header Vary Accept-Encoding; # Enable gzip for static assets gzip_static on; } # Cache API responses (adjust as needed) location ~* ^/api/ { add_header Cache-Control "no-cache, no-store, must-revalidate"; add_header Pragma "no-cache"; add_header Expires "0"; } # Rate limiting for API endpoints location ~* ^/api/ { limit_req zone=api burst=10 nodelay; limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s; } # Health check endpoint location /health { access_log off; return 200 "healthy\n"; add_header Content-Type text/plain; } # Logging access_log /var/log/nginx/bikeservice_access.log; error_log /var/log/nginx/bikeservice_error.log; # Client max body size (for file uploads) client_max_body_size 64M; # Timeouts client_body_timeout 60s; client_header_timeout 60s; send_timeout 60s; } # Rate limiting configuration (add this to http block or create separate file) # limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s; # limit_req_zone $binary_remote_addr zone=general:10m rate=30r/s;