502 Bad Gateway on certain API Calls (Laravel, Valet, nginx)

418 Views Asked by At

I'm encounter an error on my Laravel installations on my computer. On certain calls (with payloads, with bearer token, ecc.) i recieve a "502 Bad Gateway" error. This is my configuration:

  • MacOS 12.6.8
  • Valet 4.4.0
  • PHP 8.1
  • Laravel 8.12
  • nginx 1.25.2

Every other website served by Valet works perfectly via browser; If i create a test route with a simple string print api call works (in every Laravel installations). But if i use standard call with Request and Response nginx of Valet log this error:

[error] 6601#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "POST /api/login HTTP/1.1", upstream: "fastcgi://unix:/Users/MY_USER/.config/valet/valet.sock:", host: "MY_WEBSITE.test"

I didn't change anythings of my laravel source code in the meanwhile, but probably changed somethings in my configuration. The only task I perform was an update of PHP and Valet, but I was rollback to previous configuration without resolve the problem. I tried some workaround, like upgrade cgi buffer size, reinstalling the entire stack from scratch, but without resolve.

Anyone can help me to suggest some other checks? Thanks in advance

UPDATE:

I checked my valet installation (valet uninstall, valet install, tried "Fix My Valet" ); I checked php-fpm, php and laravel logs but nothings logged; I checked nginx log and my only message is the same i had posted in my first message; I increased both php memory limit and fastcgi buffer; all databases and websites in valet parked folder works; if i creare a simple laravel enpoint with a simple "test" string printed and it works found where app crashes in a 502 error. When I perform an Eloquent function. So it's limited to those actions.

So, to recap my situation: **

  • If I try the same function (e.g.: Card::find(1)) in thinker session it works perfectly
  • if a try a test API call (eg.: a simple test call with a string as response) it works perfectly
  • if I navigate su app via browser it works perfectly
  • if I try a Api call to a function of a controller where I have to perform an Eloquent query (e.g.: Card::find(1)) it responds with a 502 Bad Gateway error (with Nginx log "upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server:").**
0

There are 0 best solutions below