Skip to content

Instantly share code, notes, and snippets.

@i-amolo
Forked from weapp/nginx.conf
Created April 10, 2024 21:08
Show Gist options
  • Save i-amolo/3423534a698de9061c03fabea08c65e7 to your computer and use it in GitHub Desktop.
Save i-amolo/3423534a698de9061c03fabea08c65e7 to your computer and use it in GitHub Desktop.
Return common errors as json in Nginx
error_page 500 /500.html;
location /500.html{
return 500 '{"error": {"status_code": 500,"status": "Internal Server Error"}}';
}
error_page 502 /502.html;
location /502.html{
return 502 '{"error": {"status_code": 502,"status": "Bad Gateway"}}';
}
error_page 503 /503.html;
location /503.html{
return 503 '{"error": {"status_code": 503,"status": "Service Temporarily Unavailable"}}';
}
error_page 504 /504.html;
location /504.html{
return 504 '{"error": {"status_code": 504,"status": "Gateway Timeout"}}';
}
error_page 400 /400.html;
location /400.html{
return 400 '{"error": {"status_code": 400,"status": "Bad Request"}}';
}
error_page 401 /401.html;
location /401.html{
return 401 '{"error": {"status_code": 401,"status": "Unauthorized"}}';
}
error_page 403 /403.html;
location /403.html{
return 403 '{"error": {"status_code": 403,"status": "Forbidden"}}';
}
error_page 404 /404.html;
location /404.html{
return 404 '{"error": {"status_code": 404,"status": "Not Found"}}';
}
error_page 408 /408.html;
location /408.html{
return 408 '{"error": {"status_code": 408,"status": "Request Timeout}}';
}
error_page 418 /418.html;
location /418.html{
return 418 '{"error": {"status_code": 418,"status": "I\'m a teapot"}}';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment