server {
    listen 80;
    server_name localhost;

    # This MUST match the working_dir and volume path from your docker-compose.yml
    root /app;
    index index.php index.html;

    # Using underscores for log files
    access_log /var/log/nginx/access_log.log;
    error_log /var/log/nginx/error_log.log;

    # Route everything to index.php if the file doesn't explicitly exist
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    # Pass all .php files to the PHP-FPM container
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        
        # 'php' is the name of the service in your docker-compose.yml
        # 9000 is the default port PHP-FPM listens on
        fastcgi_pass php:9000; 
        fastcgi_index index.php;
        
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}
