Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve a PHP-FPM Primary script unknown with a PHP-FPM and an Nginx Docker container?

Tags:

php

docker

nginx

My situation is this, I have two Docker containers:

  1. Runs PHP-FPM on port 9000
  2. Runs nginx and has PHP files (should the PHP-FPM container have access to the files?)

I keep getting the following error:

FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.17.0.1, ser
ver: _, request: "GET / HTTP/1.1", upstream: "fastcgi://172.17.0.2:9000", host: "172.17.0.3"

I read here that this is "always related to a wrongly set SCRIPT_FILENAME in the nginx fastcgi_param directive."

The problem is, I don't know how to resolve it :-P

Config in Container 2:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    charset UTF-8;
    root /var/www/WordPress;

    index index.php index.html index.htm;
    server_name _;
    location / {
        try_files $uri/ /index.php?$args;
    }
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        fastcgi_pass 172.17.0.2:9000;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /var/www/WordPress$fastcgi_script_name;
        # set headers
        add_header Cache-Control $cc;
        access_log off;
        expires $ex;
    }
    location ~* \.(js|css|svg|png|jpg|jpeg|gif|ico|eot|otf|ttf|woff)$ {
        add_header Access-Control-Allow-Origin *;
        add_header Cache-Control "public";
        access_log off;
        log_not_found off;
        expires 1y;
    }
    location ~ /\.ht {
           deny all;
    }
}
like image 715
Bob van Luijt Avatar asked Dec 14 '16 19:12

Bob van Luijt


1 Answers

Change root line to: root /var/www/WordPress/; for the $fastcgi_script_name doesn't include /

like image 104
Jason Peng Avatar answered Sep 25 '22 09:09

Jason Peng