代码之家  ›  专栏  ›  技术社区  ›  shichen

PHP-FPM+Nginx设置保活导致响应错误?

  •  0
  • shichen  · 技术社区  · 1 年前

    我设置了PHP-FPM和Nginx来维护持久连接。然而,在高并发场景中,响应不正确,导致前端直接显示网页的源代码。经过测试,我发现错误的页面包含来自其他页面的内容,并且请求-响应和响应主体中没有空行。

    upstream fpm {
        server we-fpm:18074;
        keepalive 32;
    }
    location ~ [^/]\.php(/|$)
    {
        try_files $uri =404;
        fastcgi_pass fpm;
        ...
    }
    

    在高并发场景中,有时可能会发生以下响应(curl),将响应体视为响应头

    > GET /xxxxx/xxxx/xxxx HTTP/1.1
    > Host: 127.0.0.1:8074
    > Accept: */*
    > User-Agent: 20230520194633
    >
    < HTTP/1.1 200 OK
    < Server: nginx
    < Date: Sat, 20 May 2023 11:46:33 GMT
    < Transfer-Encoding: chunked
    < Connection: keep-alive
    < <!DOCTYPE html>:
    < <html lang="en">:
    
            p {
                margin: 0;
                font-size: 14px;
            }
    ===== the page i don't kown how come ====
    </script>
    </body>
    </htmlX-Powered-By: PHP/7.4.30
    Set-Cookie: PHPSESSID=5fvq4esv0v9ho3k66ug7nfmrcd; path=/; HttpOnly
    Cache-Control: no-cache
    Content-Type: text/html; charset=UTF-8
    Date: Sat, 20 May 2023 11:46:33 GMT
    
    <!DOCTYPE html>
    <html lang="en">
    ====the page i want===
    </html>
    

    正确的反应是

    <!DOCTYPE html>
    <html lang="en">
    ====the page i want===
    </html>
    

    我不知道下面的内容是怎么来的。

    < <!DOCTYPE html>:
    < <html lang="en">:
    
            p {
                margin: 0;
                font-size: 14px;
            }
    ...
    </script>
    </body>
    </html
    
    0 回复  |  直到 1 年前