ChatGPT解决这个技术问题 Extra ChatGPT

上游从上游读取响应标头时发送了太大的标头

我收到这些错误:

2014/05/24 11:49:06 [错误] 8376#0: *54031 上游从上游读取响应标头时发送的标头太大,客户端:107.21.193.210,服务器:aamjanata.com,请求:“GET /the-洗脑-编年史-由gujarat-government/赞助,%20https:/aamjanata.com/the-brainwash-chronicles-owned-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-赞助-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-owned-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-赞助-by- gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-owned-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-owned-by-gujarat-government/ ,%20https:/aamjanata.com/the-brainwash-chronicles-owned-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-owned-by-gujarat-government/,%20https: /aamjanata.com/the-brainwash-chronicles-owned-by-gujarat-government/,%20https://aamjanata.com/t he-brainwash-chronicles-owned-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-owned-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash- Chronicles-owned-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-owned-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-owned- by-gujarat-government/,%20https://aamjanata.com/the-brainwash-chronicles-owned-by-gujarat-government/,%20https://aamjanata.com/the-brainwash-chronicles-owned-by-gujarat -government/,%20https:/aamjanata.com/the-brainwash-chronicles-owned-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-owned-by-gujarat-government/, %20https:/aamjanata.com/the-brainwash-chronicles-owned-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-owned-by-gujarat-government/,%20https:/ aamjanata.com/the-brainwash-chronicles-supported-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-ch由古吉拉特邦政府赞助的 ronicles/,%20ht

总是一样的。一个以逗号分隔的网址一遍又一遍地重复。无法弄清楚是什么原因造成的。有人有想法吗?

更新:另一个错误:

http request count is zero while sending response to client

这是配置。还有其他不相关的东西,但这部分是添加/编辑的

fastcgi_cache_path /var/nginx-cache levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
proxy_buffer_size   128k;
proxy_buffers   4 256k;
proxy_busy_buffers_size   256k;
    # Upstream to abstract backend connection(s) for PHP.
    upstream php {
            #this should match value of "listen" directive in php-fpm pool
            server unix:/var/run/php5-fpm.sock;
    }

然后在服务器块中: set $skip_cache 0;

    # POST requests and urls with a query string should always go to PHP
    if ($request_method = POST) {
            set $skip_cache 1;
    }
    if ($query_string != "") {
            set $skip_cache 1;
    }

    # Don't cache uris containing the following segments
    if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
            set $skip_cache 1;
    }

    # Don't use the cache for logged in users or recent commenters
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
            set $skip_cache 1;
    }

    location / {
            # This is cool because no php is touched for static content.
            # include the "?$args" part so non-default permalinks doesn't break when using query string
            try_files $uri $uri/ /index.php?$args;
    }


    location ~ \.php$ {
            try_files $uri /index.php;
            include fastcgi_params;
            fastcgi_pass php;
            fastcgi_read_timeout 3000;

            fastcgi_cache_bypass $skip_cache;
            fastcgi_no_cache $skip_cache;

            fastcgi_cache WORDPRESS;
            fastcgi_cache_valid  60m;
    }

    location ~ /purge(/.*) {
        fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
    }`
您的代理配置似乎不正确。可以分享一下配置吗?
您可以尝试添加:fastcgi_buffers 16 16k; fastcgi_buffer_size 32k;

N
Neo

将以下内容添加到您的 conf 文件中

fastcgi_buffers 16 16k; 
fastcgi_buffer_size 32k;

虽然您的回答使我得到了正确的响应,但您应该展示如何确定正确的缓冲区大小以及为什么这很重要。否则就是在黑暗中开枪。请参阅此处了解有关大小的想法:gist.github.com/magnetikonline/…
“fastcgi_buffer_size 32k;”单独不起作用,我需要两条线来重启 NginX。我来到这里是因为 WordPress 插件导致 NginX 出现 502 错误。
如果 fast_cgi_buffers 没有帮助,请尝试 @amd 的 proxy_buffers answer below
请对此答案进行任何解释。
它对我有用,我只想在 ubuntu 16.04 中添加 nginx 配置文件位于 /etc/nginx/nginx.conf 并且值应该放在 http {...}
i
icc97

如果 nginx 作为代理/反向代理运行

也就是说,对于 ngx_http_proxy_module 的用户

除了 fastcgiproxy 模块还将请求标头保存在临时缓冲区中。

因此您可能还需要增加 proxy_buffer_sizeproxy_buffers,或完全禁用它(请阅读 nginx documentation)。

代理缓冲配置示例

http {
  proxy_buffer_size   128k;
  proxy_buffers   4 256k;
  proxy_busy_buffers_size   256k;
}

禁用代理缓冲区的示例(推荐用于长轮询服务器)

http {
  proxy_buffering off;
}

有关详细信息:Nginx proxy module documentation


“proxy_busy_buffers_size”必须小于所有“proxy_buffers”的大小减去一个缓冲区
你是男人!谢谢!第一个选项在我的 ruby on rails 应用程序中工作
可能是一个愚蠢的问题,但我在返回此错误的服务器前面有一个代理。更改缓冲区有效,但内部机器出现新错误。 writev() failed (104: Connection reset by peer) while sending to client 这些代理设置可能会修复该错误,并且会在上游服务器或代理上继续吗?
为什么是 proxy_buffers 4 ... ?由于默认值似乎是 8
对我来说,尽管设置了缓冲,设置缓冲区仍然是必要的......
i
icc97

Plesk 说明

我在这里结合了前两个答案

在 Plesk 12 中,我让 nginx 作为反向代理运行(我认为这是默认代理)。因此当前的 top answer 不起作用,因为 nginx 也作为代理运行。

我去了Subscriptions | [subscription domain] | Websites & Domains (tab) | [Virtual Host domain] | Web Server Settings

然后在该页面的底部,您可以设置 Additional nginx 指令,我将其设置为此处前两个答案的组合:

fastcgi_buffers         16  16k;
fastcgi_buffer_size         32k;
proxy_buffer_size          128k;
proxy_buffers            4 256k;
proxy_busy_buffers_size    256k;

在哪里?哪个配置?
@Redsandro 如果您无法通过 Subscriptions | [subscription domain] | Websites & Domains (tab) | [Virtual Host domain] | Web Server Settings 找到它,那么我不确定您的意思是什么?
这是我的解决方案:域 > 域名 > Apache & nginx 设置 > 附加 nginx 指令 Plesk Onyx 版本 17.8.11
我在一个新文件 /etc/nginx/conf.d/proxy.conf 中添加了这个并重新启动了 nginx,它工作正常,谢谢!
p
ppostma1

upstream sent too big header while reading response header from upstream 是 nginx 表达“我不喜欢我所看到的”的通用方式

你的上游服务器线程崩溃了上游服务器发回了一个无效的标头从 STDERR 发回的通知/警告溢出了他们的缓冲区,它和 STDOUT 都被关闭了

3:查看消息上方的错误日志,是否在消息之前记录了行? PHP message: PHP Notice: Undefined index: 来自循环我的日志文件的示例片段:

2015/11/23 10:30:02 [error] 32451#0: *580927 FastCGI sent in stderr: "PHP message: PHP Notice:  Undefined index: Firstname in /srv/www/classes/data_convert.php on line 1090
PHP message: PHP Notice:  Undefined index: Lastname in /srv/www/classes/data_convert.php on line 1090
... // 20 lines of same
PHP message: PHP Notice:  Undefined index: Firstname in /srv/www/classes/data_convert.php on line 1090
PHP message: PHP Notice:  Undefined index: Lastname in /srv/www/classes/data_convert.php on line 1090
PHP message: PHP Notice:  Undef
2015/11/23 10:30:02 [error] 32451#0: *580927 FastCGI sent in stderr: "ta_convert.php on line 1090
PHP message: PHP Notice:  Undefined index: Firstname

您可以在底部的第 3 行中看到缓冲区限制已被击中、损坏,并且下一个线程在其上写入。 Nginx 然后关闭连接并向客户端返回 502。

2:记录每个请求发送的所有标头,检查它们并确保它们符合标准(nginx 不允许超过 24 小时的任何内容删除/过期 cookie,发送无效的内容长度,因为错误消息在内容计数之前被缓冲。 ..)。 getallheaders 函数调用通常可以在抽象代码情况下提供帮助php get all headers

例子包括:

<?php
//expire cookie
setcookie ( 'bookmark', '', strtotime('2012-01-01 00:00:00') );
// nginx will refuse this header response, too far past to accept
....
?>

和这个:

<?php
header('Content-type: image/jpg');
?>

<?php   //a space was injected into the output above this line
header('Content-length: ' . filesize('image.jpg') );
echo file_get_contents('image.jpg');
// error! the response is now 1-byte longer than header!!
?>

1:验证或制作脚本日志,以确保您的线程到达正确的终点并且在完成之前不退出。


这个答案一针见血。有时不仅仅是 nginx 的配置,而是实际生成标头的内容。当 error_reporting 包含通知但 display_errors 在 php.ini 中关闭时,所有消息都显示在 FCGI 标头而不是内容中。
罪魁祸首原来是我发送给stderr的东西,所以谢谢你的回答
c
camole

我有一个部署到 EBS 的 django 应用程序,并且我使用的是在 64 位 Amazon Linux 2 上运行的 Python 3.8。以下方法对我有用(注意,如果您使用的是以前的 Linux 版本,文件夹结构可能会有所不同。有关更多信息,请参阅 {1 }

创建 .platform 文件夹及其子目录,如下所示:

|-- .ebextensions          # Don't put nginx config here
|   |-- django.config        
|-- .platform              # Make ".platform" folder and its subfolders
    |-- nginx                
    |   -- conf.d
    |       -- proxy.conf

请注意,proxy.conf 文件应放在 .platform 文件夹中,而不是 .ebextensions 文件夹或 .elasticbeanstalk 文件夹中。扩展名应以 .conf NOT .config 结尾。

在 proxy.conf 文件中,直接复制并粘贴以下行:

client_max_body_size 50M;
large_client_header_buffers 4 32k;
fastcgi_buffers 16 32k;
fastcgi_buffer_size 32k;
proxy_buffer_size   128k;
proxy_buffers   4 256k;
proxy_busy_buffers_size   256k;

无需发出命令重启 nginx(适用于 Amazon Linux 2)

再次将源代码部署到 elastic beanstalk。


伙计,这太疯狂了……它解决了我的问题。我正在使用在 64 位 Amazon Linux 2/5.3.2 上运行的 Elastic Beanstalk Node.js 14。
即使它不是 Beanstalk 环境,它也可以工作。它解决了我的问题。
l
lyte

我们最终意识到我们的一台服务器正在经历这种情况,它破坏了 fpm 配置,导致通常记录到磁盘的 php 错误/警告/通知正在通过 FCGI 套接字发送。当部分标头跨缓冲区块拆分时,似乎存在解析错误。

因此,将 php_admin_value[error_log] 设置为实际可写的内容并重新启动 php-fpm 就足以解决问题。

我们可以用更小的脚本重现这个问题:

<?php
for ($i = 0; $i<$_GET['iterations']; $i++)
    error_log(str_pad("a", $_GET['size'], "a"));
echo "got here\n";

提高缓冲区使 502 更难命中但并非不可能,例如原生:

bash-4.1# for it in {30..200..3}; do for size in {100..250..3}; do echo "size=$size iterations=$it $(curl -sv "http://localhost/debug.php?size=$size&iterations=$it" 2>&1 | egrep '^< HTTP')"; done; done | grep 502 | head
size=121 iterations=30 < HTTP/1.1 502 Bad Gateway
size=109 iterations=33 < HTTP/1.1 502 Bad Gateway
size=232 iterations=33 < HTTP/1.1 502 Bad Gateway
size=241 iterations=48 < HTTP/1.1 502 Bad Gateway
size=145 iterations=51 < HTTP/1.1 502 Bad Gateway
size=226 iterations=51 < HTTP/1.1 502 Bad Gateway
size=190 iterations=60 < HTTP/1.1 502 Bad Gateway
size=115 iterations=63 < HTTP/1.1 502 Bad Gateway
size=109 iterations=66 < HTTP/1.1 502 Bad Gateway
size=163 iterations=69 < HTTP/1.1 502 Bad Gateway
[... there would be more here, but I piped through head ...]

fastcgi_buffers 16 16k; fastcgi_buffer_size 32k;

bash-4.1# for it in {30..200..3}; do for size in {100..250..3}; do echo "size=$size iterations=$it $(curl -sv "http://localhost/debug.php?size=$size&iterations=$it" 2>&1 | egrep '^< HTTP')"; done; done | grep 502 | head
size=223 iterations=69 < HTTP/1.1 502 Bad Gateway
size=184 iterations=165 < HTTP/1.1 502 Bad Gateway
size=151 iterations=198 < HTTP/1.1 502 Bad Gateway

所以我相信正确的答案是:修复您的 fpm 配置,以便将错误记录到磁盘。


您是说当部分标头跨缓冲区块拆分时,可能是 nginx 解析错误?
当时肯定是这样的
A
Atila Pehlivan
fastcgi_busy_buffers_size 512k;
fastcgi_buffer_size 512k;
fastcgi_buffers 16 512k;

当我增加数字时它对我有用


L
Lucas Bustamante

如果您使用的是 Symfony 框架:在弄乱 Nginx 配置之前,请先尝试禁用 ChromePHP。

- 打开 app/config/config_dev.yml

2 - 评论这些行:

#chromephp:
    #type:   chromephp
    #level:  info

ChromePHP 将调试信息 json-encoded 打包在 X-ChromePhp-Data 标头中,这对于带有 fastcgi 的 nginx 的默认配置来说太大了。

来源:https://github.com/symfony/symfony/issues/8413#issuecomment-20412848


J
Jorge Cuerdo

添加:

fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
proxy_buffer_size   128k;
proxy_buffers   4 256k;
proxy_busy_buffers_size   256k;

到 nginx.conf 中的服务器{}

为我工作。


I
Ilia Yatsenko

在 php-fpm 和 docker 容器中的 nginx 中运行 Symfony 应用程序时遇到了同样的问题。

经过一番研究发现是php-fpm的stderr写入nginx日志造成的。即 php 警告(在 Symfony 调试模式下密集生成)在 docker logs php-fpm 中重复:

[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: ""
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: "NOTICE: PHP message: [debug] Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\DisallowRobotsIndexingListener::onResponse"."
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: ""
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: "NOTICE: PHP message: [debug] Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\StreamedResponseListener::onKernelResponse"."
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: ""
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: "NOTICE: PHP message: [debug] Notified event "kernel.finish_request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelFinishRequest"."
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: ""
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: "NOTICE: PHP message: [debug] Notified event "kernel.finish_request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelFinishRequest"."
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: ""
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: "NOTICE: PHP message: [debug] Notified event "kernel.finish_request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleAwareListener::onKernelFinishRequest"."
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: ""
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: "NOTICE: PHP message: [debug] Notified event "kernel.terminate" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelTerminate"."
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: ""

docker logs nginx

2021/07/09 12:25:46 [error] 30#30: *2 FastCGI sent in stderr: "ller" to listener "OblgazAPI\API\Common\Infrastructure\EventSubscriber\LegalAuthenticationChecker::checkAuthentication".

PHP message: [debug] Notified event "kernel.controller_arguments" to listener "Symfony\Component\HttpKernel\EventListener\ErrorListener::onControllerArguments".

PHP message: [debug] Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse".

PHP message: [debug] Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelResponse".

PHP message: [debug] Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse".

PHP message: [debug] Notified event "kernel.response" to listener "Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse".

PHP message: [debug] Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\DisallowRobotsIndexingListener::onResponse".

PHP message: [debug] Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\StreamedResponseListener::onKernelResponse".

PHP message: [debug] Notified event "kernel.finish_request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelFinishRequest".

PHP message: [debug] Notified event "kernel.finish_request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelFinishRequest".

PHP message: [debug] Notified event "kernel.finish_request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleAwareListener::onKernelFinishRequest".

PHP message: [debug] Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ErrorListener::logKernelException".

PHP message: [debug] Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException".

然后nginx日志以

2021/07/09 12:25:46 [error] 30#30: *2 upstream sent too big header while reading response header from upstream ...

我得到 502 错误。

在 nginx 配置中增加 fastcgi_buffer_size 有所帮助,但它似乎更像是抑制问题,而不是治疗。

更好的解决方案是禁用 php-fpm 通过 FastCGI 发送日志。发现可以通过在php.ini中设置fastcgi.logging=0来实现(默认为1)。 php docs

将其更改为 0 后,问题就消失了,nginx 日志看起来更干净了 docker logs nginx

172.18.0.1 - - [09/Jul/2021:12:36:02 +0300] "GET /my/symfony/app HTTP/1.1" 401 73 "-" "PostmanRuntime/7.26.8"
172.18.0.1 - - [09/Jul/2021:12:36:04 +0300] "GET /my/symfony/app HTTP/1.1" 401 73 "-" "PostmanRuntime/7.26.8"

并且所有 php-fpm 日志仍在 php-fpm 日志中的位置。


D
DavidKunz

在搜索此错误时,这仍然是 Google 上最高的 SO-question,所以让我们碰一下。

当遇到此错误并且不想立即深入研究 NGINX 设置时,您可能需要检查调试控制台的输出。在我的情况下,我将大量文本输出到 FirePHP / Chromelogger 控制台,并且由于这都是作为标头发送的,因此导致了溢出。

如果此错误是由发送大量日志消息引起的,则可能不需要更改 Web 服务器设置。


m
macherif

我不确定这个问题是否与 php 发送的标头有关。确保启用缓冲。简单的方法是创建一个 proxy.conf 文件:

proxy_redirect          off;
proxy_set_header        Host            $host;
proxy_set_header        X-Real-IP       $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size    100m;
client_body_buffer_size 128k;
proxy_connect_timeout   90;
proxy_send_timeout      90;
proxy_read_timeout      90;
proxy_buffering         on;
proxy_buffer_size       128k;
proxy_buffers           4 256k;
proxy_busy_buffers_size 256k;

还有一个 fascgi.conf 文件:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
fastcgi_buffers 128 4096k;
fastcgi_buffer_size 4096k;
fastcgi_index  index.php;
fastcgi_param  REDIRECT_STATUS    200;

接下来,您需要以这种方式在默认配置服务器中调用它们:

http {
  include    /etc/nginx/mime.types;
  include    /etc/nginx/proxy.conf;
  include    /etc/nginx/fastcgi.conf;
  index    index.html index.htm index.php;
  log_format   main '$remote_addr - $remote_user [$time_local]  $status '
    '"$request" $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';
  #access_log   /logs/access.log  main;
  sendfile     on;
  tcp_nopush   on;
 # ........
}

M
Michał Moskal

对于 Symfony 项目,尝试将此行添加到您的 .env 文件中:

SHELL_VERBOSITY=0

https://symfony.com/doc/current/console/verbosity.html

我将把它留在这里,因为我在我的项目中花费了大量时间来调试它,只有这个特定的解决方案对我来说 100% 有效(出于正确的原因),而且我从来没有找到与这个主题相关的答案。也许有人会发现它有帮助。


O
Oleg Dmitrochenko

我遇到了这个错误,我找到了 3 种方法来解决这个问题:

在 .env 中设置 SHELL_VERBOSITY=0 或其他值 < 3:https://stackoverflow.com/a/69321273/13653732 在这种情况下,您禁用 PHP 日志,但它们对于开发和调试很有用。

在 php.ini 中设置 fastcgi.logging=0。与上面的结果相同。

将 Symfony 从 5.2 更新到 5.3。我认为旧版本有问题。

所有 PHP Symfony 日志都被视为 Nginx 的错误,但 PHP 工作正常。

我有 Nginx 1.17、PHP 8.0.2、PHP-FPM、Symfony 5.2、Xdebug、Docker。

我尝试了新版本的 Nginx 1.21、PHP 8.0.14,但没有任何结果。那个问题不在于 Apache。

我更改了 Nginx 配置,但也没有任何结果。


SHELL_VERBOSITY=0 为我工作
y
yesnik

在我们的例子中,我们收到了这个 nginx 错误,因为我们的后端生成了带有很长 URL 的重定向响应:

HTTP/1.1 301 Moved Permanently 
Location: https://www.example.com/?manyParamsHere...

出于好奇,我们将那个大 URL 保存到一个文件中,它的大小为 4.4 Kb。

在配置文件 /etc/nginx/conf.d/some_site.conf 中添加两行有助于我们修复此错误:

server {
    # ...
    location ~ ^/index\.php(/|$) {
        fastcgi_pass php-upstream;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        # Add these lines:
        fastcgi_buffer_size 32k;
        fastcgi_buffers 4 32k;
    }
}

在官方 nginx documentation 中阅读有关这些参数的更多信息。


请解释为什么要添加这些行。
p
pscheit

我正在使用 Symfony,它有一个很好的异常页面(使用 ErrorHandler 时)。这会将您的异常消息作为创建响应的标头。

供应商/symfony/错误处理程序/ErrorRenderer/SerializerErrorRenderer.php

标题被称为:X-Debug-Exception

所以要小心,如果你构建了一个非常大的异常消息,无论是 nginx 还是 chrome(限制 256k)还是 curl(~128kb)都不能显示你的页面,并且很难调试,输出那些大标题的是什么。

我的建议是不要盲目地将 n 粘贴增加的缓冲区大小复制到您的 nginx 配置中,他们对待症状而不是原因。