-
-
Save paulobunga/5e65f7d9e426d61b26026d19e73fd138 to your computer and use it in GitHub Desktop.
beautiful html5 error pages for nginx; applied globally for each server block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this belongs inside a 'server {}' block | |
# I propose you put this in a file somewhere, e.g. /etc/nginx/error_pages | |
# and then include it with an 'include error_pages;' directive | |
# | |
# see it in larger context here: | |
# https://git.semjonov.de/server/nginx-conf/tree/b63de50001b15fbb33680de14fad05230f2b8fd2 | |
# | |
# design is taken from html5-boilerplate: | |
# https://github.com/h5bp/html5-boilerplate/blob/master/src/404.html | |
error_page 400 401 403 404 500 502 503 504 /.error-docs/nope.html; | |
location ~ ^/.error-docs/nope.html { | |
add_header Content-Type text/html; | |
return 200 " | |
<!doctype html> | |
<html lang='en'> | |
<head> | |
<meta charset='utf-8'> | |
<title>$status_text</title> | |
<meta name='viewport' content='width=device-width, initial-scale=1'> | |
<style> | |
* { | |
line-height: 1.2; | |
margin: 0; } | |
html { color: #888; | |
display: table; | |
font-family: sans-serif; | |
height: 100%; | |
text-align: center; | |
width: 100%; } | |
body { display: table-cell; | |
vertical-align: middle; | |
margin: 2em auto; } | |
h1 { color: #555; | |
font-size: 3em; | |
font-weight: 400; } | |
p { padding-top: 1em; | |
margin: 0 auto; | |
width: 275px; | |
text-align: justify; } | |
@media only screen and (max-width: 280px) { | |
body, p { width: 95%; } | |
h1 { font-size: 1.5em; margin: 0 0 0.3em; } } | |
</style> | |
</head> | |
<body> | |
<h1>$status</h1> | |
<h1>$status_text</h1> | |
<p>$status_issue</p> | |
</body> | |
</html> | |
<!-- IE needs 512+ bytes: http://blogs.msdn.com/b/ieinternals/archive/2010/08/19/http-error-pages-in-internet-explorer.aspx -->"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this belongs in /etc/nginx/conf.f/ | |
# text mostly taken from http://www.restapitutorial.com/httpstatuscodes.html | |
map $status $status_text { | |
default "Unspecified Error"; | |
200 "Success"; | |
400 "Bad Request"; | |
401 "Unauthorized"; | |
403 "Forbidden"; | |
404 "Not Found"; | |
500 "Internal Server Error"; | |
502 "Bad Gateway"; | |
503 "Service Unavailable"; | |
504 "Gateway Timeout"; | |
} | |
map $status $status_issue { | |
default "Well, this should not happen."; | |
200 "The request was understood and served. This exactly what you requested."; | |
400 "The request could not be understood by the server due to malformed syntax."; | |
401 "The request requires user authentication.<br />If the request included Authorization credentials, then this error indicates that authorization has been refused for those credentials."; | |
403 "The server understood the request but is refusing to fulfill it."; | |
404 "The server has not found anything matching the Request-URI."; | |
500 "The server encountered an unexpected condition which prevented it from fulfilling the request."; | |
502 "The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request."; | |
503 "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."; | |
504 "The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server it needed to access in attempting to complete the request."; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment