matiac
matiac

Reputation: 13

I get FastCGI "Primary script unknown" error in a NGINX / PHP-FPM containers situation

Context

I've got these two docker containers connected to a network:

Both containers have access to a local directory containing the app files.

My NGINX configuration:

server {
    listen 80;
    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /usr/share/nginx/html;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    location / {
        try_files $uri $uri/ /index.php?$query_string;
        gzip_static on;
    }
}

Problem

When trying to access the site, the browser shows "File not found.".

NGINX container logs:

FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

PHP-FPM container logs:

"GET /index.php" 404

Things I've checked

Could you please point me in some direction? I'm lost.

Upvotes: 1

Views: 3767

Answers (1)

Richard Smith
Richard Smith

Reputation: 49702

The NGINX container can see that the file exists at /usr/share/nginx/html/index.php otherwise the try_files statement would be generating the 404 response rather than PHP-FPM.

So the PHP-FPM container has received the request with SCRIPT_FILENAME set to /usr/share/nginx/html/index.php but PHP cannot see the file using that pathname.

As your comment confirms, this is a discrepancy in the pathname routes between the two containers.

Upvotes: 6

Related Questions