1

Context

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

  • php:8-fpm-alpine with my web app, exposing port 9000.
  • nginx:alpine serving the app.

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

  • App is running.
  • root in NGINX config actually points to where the app files are.
  • App directory, inside the app container, has at least public read and execute rights all the way through, which should rule out access issues... right?
  • There is no other container in the network blocking port 9000.

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

2
  • The NGINX container can see that the file exists at /usr/share/nginx/html/index.php - it then passes this path to the PHP-FPM container via the SCRIPT_FILENAME variable, but PHP cannot see the file using that path. Commented Mar 15, 2022 at 9:48
  • @RichardSmith thanks to you pinpointing the problem I realized that, while both containers have acces to the app directory, both store it internally in different routes, causing the discrepancy. Please write your comment as answer so I can accept it. Commented Mar 15, 2022 at 16:18

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.