我有一个在 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
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);
}
我假设您的 Nginx 作为代理服务器运行,向 Apache(此处为上游)发送请求,它发送的 HTTP 标头比 Nginx 配置读取的更大,因此超过了 Nginx 配置中设置的缓冲区大小。尝试将缓冲区大小增加到
proxy_buffer_size
更大的值并重新启动 Nginx 服务器。这是一个很好的资源,可以调整您考虑查看的 Nginx 代理配置。