error 28105#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

10,735

Also, need to share files to the php:fpm docker container too. The answer is to run docker php:fpm image with volume too:

docker run -it -p 127.168.66.66:9000:9000 -v /var/www/html/:/var/www/html/ php:fpm
Share:
10,735
Victor Bocharsky
Author by

Victor Bocharsky

PHP Web Developer

Updated on July 02, 2022

Comments

  • Victor Bocharsky
    Victor Bocharsky almost 2 years

    I can't config Nginx with php-fpm correctly. When I get any php script, I get Nginx 404 Not found error in browser:

    File not found.
    

    In my php-fpm logs I get:

    172.17.42.1 -  28/Apr/2015:09:15:15 +0000 "GET /index.php" 404
    

    for any php script call and in Nginx logs I get:

    [error] 28105#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.168.66.66:9000", host: "localhost"
    

    My Nginx vitualhost config is:

    server {
      listen 80;
    
      root /var/www/html;
      index index.html;
    
      server_name localhost;
    
      location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
      }
    
      location ~* \.php$ {
        fastcgi_index   index.php;
        fastcgi_pass    127.168.66.66:9000;
        #fastcgi_pass    unix:/var/run/php5-fpm.sock;
        include         fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
      }
    }
    

    I had spinning php-fpm Docker image from official php repository, that run by:

    docker run -it -p 127.168.66.66:9000:9000 php:fpm
    

    The docker ps command show next info:

    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                          NAMES
    dbf9f7d1c6f9        php:fpm             "php-fpm"           8 seconds ago       Up 7 seconds        127.168.66.66:9000->9000/tcp   serene_curie 
    

    What's wrong with my config?

    P.S. Any static files (css, js, images) works on Nginx.

    • Victor Bocharsky
      Victor Bocharsky about 9 years
      Sorry guys! I don't know that I also must to share my files to my php:fpm docker container too. I think it must work without sharing. The answer is to run docker image with volume: docker run -it -p 127.168.66.66:9000:9000 -v /var/www/html/:/var/www/html/ php:fpm
    • oOo--STAR--oOo
      oOo--STAR--oOo about 9 years
      I am having the exact same problem as you.. I trying this on a new setup on centos 7 using PHP 5.6.8 (fpm-fcgi) (built: Apr 16 2015 14:45:51) All my configs are setup correctly and I get file not found.. Have you managed to find the culprit as changing the fastcgi_param for the scripts to execute is not working and I have tried multiple params.
    • Victor Bocharsky
      Victor Bocharsky almost 9 years
      @oOo--STAR--oOo I fixed it. I forgot to share my files to the container and fpm throw this error
  • besrabasant
    besrabasant over 2 years
    One more thing to note is that the nginx root directive path and docker volume destination path should be same.