首页 > 解决方案 > 隐身模式下的 Nginx 502 错误

问题描述

我的 NGINX 服务器出现了一个奇怪的问题。该网站打开并在浏览隐身模式时正常运行,但是对于任何新的浏览器/会话,我都会收到 NGINX 502 Bad Gateway 错误。我在错误日志中只有以下内容。

[错误] 2121#2121: *34 上游从上游读取响应标头时发送的标头太大,客户端:xx.xx.xx.xx,服务器:domain.tld,请求:“GET / HTTP/2.0”,上游:“ fastcgi://unix:/run/php/php7.2-fpm.sock:",主机:"domain.tld"

配置文件已附上

server {

server_name domain.tld  www.domain.tld;

root   /var/www/html/domain.tld/public_html;
index  index.html index.php;
http2_push_preload on;

location / {
    try_files $uri $uri/ /index.php?$args;
    proxy_buffer_size          128k;
    proxy_buffers              4 256k;
    proxy_busy_buffers_size    256k;
    }
location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME /var/www/html/domain.tld/public_html$fastcgi_script_name;
}

    location = /xmlrpc.php {
        deny all;
        }

    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt { log_not_found off; access_log off; allow all; }
            location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
    expires max;
    log_not_found off;
}

    location ~ /\.ht {
    deny all;
}

location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
    add_header "" "";
    }

location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
# managed by Certbot

listen 443 ssl http2; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}
server {
if ($host = www.domain.tld) {
    return 301 https://$host$request_uri;
} # managed by Certbot


if ($host = domain.tld) {
    return 301 https://$host$request_uri;
} # managed by Certbot



server_name domain.tld www.domain.tld;
listen 80;
return 404; # managed by Certbot
}

标签: wordpressnginxserver-administration

解决方案


通过将以下指令添加到我的 nginx 配置文件来修复它

fastcgi_max_temp_file_size 0;
fastcgi_buffers 128 2048k;
fastcgi_buffer_size 2048k;

希望它可以帮助无法修复此错误的人:)


推荐阅读