Nginx return an empty json object with fake 200 status code Nginx return an empty json object with fake 200 status code json json

Nginx return an empty json object with fake 200 status code


error_page 404 =200 @empty_json;location @empty_json {     return 200 "{}";}

Reference:


You can always create a file in your document root called e.g. empty.json which only contains an empty object {}

Then in your nginx configuration add this line in your location block

try_files $uri /empty.json;

( read more about try_files )

This will check if the file requested by the client exists and if it does not exist it just shows empty.json instead. This produces a 200 HTTP OK and shows a {} to the requesting client.