Return JSON for 404 error instead of html

Valentin V. Bartenev vbart at nginx.com
Tue May 13 09:01:08 UTC 2014


On Monday 12 May 2014 23:42:03 Lord Nynex wrote:
> Justink101,
> 
> Using the echo module
> 
> error_page 404 @404;
> location @404 { echo '{"status": "Not Found"}'; }
> 
[..]

Instead of using 3rd-party echo module, you can utilize the return directive
for the same purpose:

  return 200 '{"status": "Not Found"}';

Reference: http://nginx.org/r/return

  wbr, Valentin V. Bartenev



More information about the nginx mailing list