Skip to content

Instantly share code, notes, and snippets.

@weapp
Last active August 29, 2015 14:21
Show Gist options
  • Save weapp/9a3fd2c068cb206e9d40 to your computer and use it in GitHub Desktop.
Save weapp/9a3fd2c068cb206e9d40 to your computer and use it in GitHub Desktop.
map $status $error_msg {
default "";
500 "Internal Server Error";
502 "Bad Gateway";
503 "Service Temporarily Unavailable";
504 "Gateway Timeout";
400 "Bad Request";
401 "Unauthorized";
403 "Forbidden";
404 "Not Found";
408 "Request Timeout";
418 "I\'m a teapot";
}
server {
listen 80;
server_name example.com;
root /home/manu/project/example;
index index.html;
error_page 400 401 403 404 408 418 500 502 503 504 /$status.json;
location /500 { return 500 '{"errors": [{"code": "$status", "message": "$error_msg"}]}'; }
location /502 { return 502 '{"errors": [{"code": "$status", "message": "$error_msg"}]}'; }
location /503 { return 503 '{"errors": [{"code": "$status", "message": "$error_msg"}]}'; }
location /504 { return 504 '{"errors": [{"code": "$status", "message": "$error_msg"}]}'; }
location /400 { return 400 '{"errors": [{"code": "$status", "message": "$error_msg"}]}'; }
location /401 { return 401 '{"errors": [{"code": "$status", "message": "$error_msg"}]}'; }
location /403 { return 403 '{"errors": [{"code": "$status", "message": "$error_msg"}]}'; }
location /404 { return 404 '{"errors": [{"code": "$status", "message": "$error_msg"}]}'; }
location /408 { return 408 '{"errors": [{"code": "$status", "message": "$error_msg"}]}'; }
location /418 { return 418 '{"errors": [{"code": "$status", "message": "$error_msg"}]}'; }
location / {
proxy_pass http://rails;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $http_host;
#proxy_set_header Host static.example.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_intercept_errors on;
}
}
@weapp
Copy link
Author

weapp commented May 19, 2015

{
      400 => 'Bad Request',
      401 => 'Unauthorized',
      402 => 'Payment Required',
      403 => 'Forbidden',
      404 => 'Not Found',
      405 => 'Method Not Allowed',
      406 => 'Not Acceptable',
      407 => 'Proxy Authentication Required',
      408 => 'Request Timeout',
      409 => 'Conflict',
      410 => 'Gone',
      411 => 'Length Required',
      412 => 'Precondition Failed',
      413 => 'Payload Too Large',
      414 => 'URI Too Long',
      415 => 'Unsupported Media Type',
      416 => 'Range Not Satisfiable',
      417 => 'Expectation Failed',
      422 => 'Unprocessable Entity',
      423 => 'Locked',
      424 => 'Failed Dependency',
      426 => 'Upgrade Required',
      428 => 'Precondition Required',
      429 => 'Too Many Requests',
      431 => 'Request Header Fields Too Large',
      500 => 'Internal Server Error',
      501 => 'Not Implemented',
      502 => 'Bad Gateway',
      503 => 'Service Unavailable',
      504 => 'Gateway Timeout',
      505 => 'HTTP Version Not Supported',
      506 => 'Variant Also Negotiates',
      507 => 'Insufficient Storage',
      508 => 'Loop Detected',
      510 => 'Not Extended',
      511 => 'Network Authentication Required'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment