server {
    # Listen on port 80
    listen 80;
    server_name localhost;

    # Root directory and index files
    root /var/www/public;
    index index.php index.html;

    # Logging
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    # Try files or directories, fallback to PHP
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    # Handle PHP files
    location ~ \.php$ {
        # Pass to PHP container
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        
        # Important! This tells PHP what file to process
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        
        # Include standard FastCGI parameters
        include fastcgi_params;

        # Some extra settings for better performance
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
    }

    # Deny access to hidden files
    location ~ /\. {
        deny all;
    }
}