Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rohansinghrawat's avatar

kevent() reported about an closed connection (54: Connection reset by peer) while reading response header from upstream

Hey everyone,

I've been facing an issue with my Laravel application lately. Whenever it interacts with certain MongoDB models, I encounter a 502 Bad Gateway error from Nginx. Upon checking the error log, I found the following error message:

*3 kevent() reported about a closed connection (54: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: api.localhost, request: "POST /auth/validateUserForLogin HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "api.localhost"

Interestingly, the issue only arises when I access the application through the Nginx port (api.localhost/xx/yy/zz). However, when I use php artisan serve to access the Laravel's port (127.0.0.1:8000/xx/yy/zz), everything works perfectly fine.

I suspect there might be an issue with Nginx and PHP-FPM, but I'm having trouble pinpointing the exact cause. I can't recall making any significant changes that could have triggered this error.

Could someone please help me troubleshoot this issue? Thanks in advance!

0 likes
2 replies
proilyxa's avatar

Add following lines to /opt/homebrew/etc/php/8.3/php-fpm.d/www.conf: env['PGGSSENCMODE'] = disable

env['LC_ALL'] = C

Then restart PHP.

1 like
tokoiwesley's avatar

@proilyxa thank you for your solution. It has worked for me! Could you please explain the reason why the issue happens in the first place? I am curious to know. I have been frustrated by this issue for over two weeks now, trying to set up Laravel 12 clean installs on my localhost, before I stumbled upon your solution.

Please or to participate in this conversation.