原创

docker nginx FastCGI sent in stderr: "Primary script unknown"

1.docker-compose.yml文件

version: '3'
services:
    php: 
        build: .
        ports:
          - "9000:9000"
        restart: always
        privileged: "true"
        volumes:
            - "$PWD/nginx/html:/var/www/html"
        networks:
            lsh:
                aliases:
                    - php56
    nginx:
        image: nginx:latest
        depends_on:
            - "php"
        volumes:
            - "$PWD/nginx/conf.d:/etc/nginx/conf.d"
            - "$PWD/nginx/html:/var/www/html"
        privileged: "true"
        ports:
            - "8011:80"
        restart: always
        networks: 
            - lsh
networks:
    lsh:
        external: true

2.报错信息

FastCGI sent in stderr: "Primary script unknown"
  • 这时候去看phpfpm的容器日志*
    2020-02-28T16:52:44.292462500Z 172.19.0.5 -  28/Feb/2020:16:52:44 +0000 "GET /a.php" 404
    
  • 这就是phpfpm没有找到脚本错误*

3.解决方案3种

1.改配置文件

location = /50x.html {
        root   /var/www/html;
    }
location ~ .*\.(php)$ {
        fastcgi_pass   php56:9000;
              fastcgi_index  index.php;
              fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
             include        fastcgi_params;
              index  index.html index.htm;
         include  fastcgi.conf;
    }

把改动配置 fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name; 这一行配置正确
默认为fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

2.可能是权限问题

把你根目录权限改成777

3.挂载共同目录解决

docker-compose.yml里面nginx和phpfpm都增加共同挂载目录可以解决,上面的yml就是解决后的配置

volumes:
            - "$PWD/nginx/html:/var/www/html"

我是第三种方法解决

正文到此结束
本文目录