【问题标题】:FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream nginx error在 stderr 中发送的 FastCGI:从上游 nginx 错误读取响应标头时出现“主脚本未知”
【发布时间】:2021-08-03 19:30:22
【问题描述】:

我使用 nginx docker 作为代理服务器,还有其他容器在运行:nuxt.jsphp-fpm

这是我的fpmconf 文件:

server {
  server_name fpm.me.com;
  root /var/www/fpm/html;

  location / {
    # try to serve file directly, fallback to index.php
    try_files $uri /index.php$is_args$args;
  }

  #location ~ ^/index\.php(/|$) {
  # https://stackoverflow.com/questions/68350978/nginx-serving-only-but-not-any-other-files
  location ~ \.php(/|$) {
    fastcgi_pass fpm:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    fastcgi_param DOCUMENT_ROOT $realpath_root;
    #internal;
  }

  location ~ \.php$ {
    return 404;
  }
  access_log off;
  error_log /dev/stderr;
}

但是当我输入fpm.me.com 时,我在nginxlog 文件中收到此错误:

2021/08/03 09:31:18 [error] 31#31: *13 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: MY_IP, server: fpm.me.com, request: "GET / HTTP/1.1", upstream: "fastcgi://172.20.0.8:9000", host: "fpm.me.com"

我在 StackOverFlow、ServerFault 和其他网站上看到了其他答案,但似乎对我没有帮助。

【问题讨论】:

    标签: php laravel docker nginx fpm


    【解决方案1】:

    这看起来无效:

    fastcgi_pass fpm:9000
    

    你有两个选择:

    • 使用 unix 套接字:

      fastcgi_pass unix:/run/php/php7.4-fpm.sock;

    • 使用 TCP 端口

      fastcgi_pass 127.0.0.1:9000;

    选项 1 稍快一些,并且如果您收到许多并发连接,则不会有端口耗尽的风险。

    【讨论】:

    • 为什么fastcgi_pass fpm:9000 无效?我在另一台服务器上使用这个 conf 文件(但只有一个应用程序和容器)。而且由于它是 dockerized,nginx 和 `fpm 是两个独立的容器
    【解决方案2】:

    问题在于我为nginxfpm 安装的volumes 不一样。

    这是我的compose 文件:

    services:
      nginx:
        image: nginx
        volumes:
          - './fpm/:/var/www/fpm/'
      fpm:
        image: custom
        volumes:
          - './fpm/:/var/www/'
    

    虽然它应该是这样工作的:

    services:
      nginx:
        image: nginx
        volumes:
          - './fpm/:/var/www/fpm/'
      fpm:
        image: custom
        volumes:
          - './fpm/:/var/www/fpm/'
    

    【讨论】:

      猜你喜欢
      • 2016-07-02
      • 2021-04-08
      • 2020-08-20
      • 2016-05-16
      • 2019-08-05
      • 2012-08-18
      • 2015-07-07
      • 2014-12-30
      • 2020-01-15
      相关资源
      最近更新 更多