In php-fpm(5.6) on nginx(1.20.1), I'm making an API that responds with http status code 500, some headers and body of json type.
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header("Access-Control-Allow-Credentials: true");
header("Content-Type: application/json");
http_response_code(500);
die(json_encode([
'errorMsg' => 'Something went wrong',
]));
But it seems the server responds without the headers and the body as clients(at least Chrome browser) don't receive them.
I tried setting a http status lower than 500 like 40x, and it made the server respond with the headers and the body as I expected.
Do other servers/applications also omit headers and body in response with http status 50x? Or it's just a problem specific to either php or nginx?