我在 Apache 服务器上运行了一个 PHP 脚本,该脚本负责断开所有用户会话。为此,它会进行一个循环,将自己标识为应断开的会话并销毁它。此过程没有回显。
Apache 日志返回 HTTP 代码 200,表示一切顺利。
但是 NGINX 返回以下错误。
[error] 512#512: *2699 upstream sent too big header while reading response header from upstream, client: <public-ip>, server: server01.example.com, request: "GET /tste.php HTTP/1.1", upstream: "http://192.168.50.2:80/tste.php", host: "server02.example.com"
什么可能导致这个问题?
PHP 脚本:
<?php
error_reporting(-1);
ini_set('display_errors', 1);
if (!function_exists('deleteSession')) {
function deleteSession($targetSessionID)
{
// 1. commit session if it's started.
if (session_id()) {
session_commit();
}
// 2. store current session id
session_start();
$current_session_id = session_id();
session_commit();
// 3. hijack then destroy session specified.
session_id($targetSessionID);
session_start();
session_destroy();
session_commit();
// 4. restore current session id. If don't restore it, your current session will refer to the session you just destroyed!
session_id($current_session_id);
session_start();
session_commit();
}
}
$sessions = [
'soadjasjosldjsaoidjasoijdsajdsaj',
'soadjasjosldjsaoidjasoijdsajdsaj',
'soadjasjosldjsaoidjasoijdsajdsaj',
'soadjasjosldjsaoidjasoijdsajdsaj',
'soadjasjosldjsaoidjasoijdsajdsaj',
'soadjasjosldjsaoidjasoijdsajdsaj',
'soadjasjosldjsaoidjasoijdsajdsaj',
'soadjasjosldjsaoidjasoijdsajdsaj',
'soadjasjosldjsaoidjasoijdsajdsaj',
'soadjasjosldjsaoidjasoijdsajdsaj',
'soadjasjosldjsaoidjasoijdsajdsaj',
'soadjasjosldjsaoidjasoijdsajdsaj',
'soadjasjosldjsaoidjasoijdsajdsaj'
];
foreach ($sessions as $session) {
deleteSession($session);
}
答案1
我假设您的 Nginx 正在作为代理服务器运行,向 Apache(此处为上游)发送请求,而 Apache 发送的 HTTP 标头比 Nginx 配置的读取值更大,因此超出了 Nginx 配置中设置的缓冲区大小。尝试将缓冲区大小增加到proxy_buffer_size
更大的值,然后重新启动 Nginx 服务器。
以下是一个很好的资源,可以调整您的 Nginx 代理配置,您可以考虑看看。