mirror of
https://github.com/joppuyo/nice-nginx-error-page.git
synced 2026-03-08 00:42:22 +00:00
Initial commit
This commit is contained in:
11
.editorconfig
Normal file
11
.editorconfig
Normal file
@@ -0,0 +1,11 @@
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
|
||||
[*.html]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[*.css]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
121
LICENSE.txt
Normal file
121
LICENSE.txt
Normal file
@@ -0,0 +1,121 @@
|
||||
Creative Commons Legal Code
|
||||
|
||||
CC0 1.0 Universal
|
||||
|
||||
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
||||
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
||||
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
||||
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
||||
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
||||
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
||||
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
||||
HEREUNDER.
|
||||
|
||||
Statement of Purpose
|
||||
|
||||
The laws of most jurisdictions throughout the world automatically confer
|
||||
exclusive Copyright and Related Rights (defined below) upon the creator
|
||||
and subsequent owner(s) (each and all, an "owner") of an original work of
|
||||
authorship and/or a database (each, a "Work").
|
||||
|
||||
Certain owners wish to permanently relinquish those rights to a Work for
|
||||
the purpose of contributing to a commons of creative, cultural and
|
||||
scientific works ("Commons") that the public can reliably and without fear
|
||||
of later claims of infringement build upon, modify, incorporate in other
|
||||
works, reuse and redistribute as freely as possible in any form whatsoever
|
||||
and for any purposes, including without limitation commercial purposes.
|
||||
These owners may contribute to the Commons to promote the ideal of a free
|
||||
culture and the further production of creative, cultural and scientific
|
||||
works, or to gain reputation or greater distribution for their Work in
|
||||
part through the use and efforts of others.
|
||||
|
||||
For these and/or other purposes and motivations, and without any
|
||||
expectation of additional consideration or compensation, the person
|
||||
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
||||
is an owner of Copyright and Related Rights in the Work, voluntarily
|
||||
elects to apply CC0 to the Work and publicly distribute the Work under its
|
||||
terms, with knowledge of his or her Copyright and Related Rights in the
|
||||
Work and the meaning and intended legal effect of CC0 on those rights.
|
||||
|
||||
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||
protected by copyright and related or neighboring rights ("Copyright and
|
||||
Related Rights"). Copyright and Related Rights include, but are not
|
||||
limited to, the following:
|
||||
|
||||
i. the right to reproduce, adapt, distribute, perform, display,
|
||||
communicate, and translate a Work;
|
||||
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||
iii. publicity and privacy rights pertaining to a person's image or
|
||||
likeness depicted in a Work;
|
||||
iv. rights protecting against unfair competition in regards to a Work,
|
||||
subject to the limitations in paragraph 4(a), below;
|
||||
v. rights protecting the extraction, dissemination, use and reuse of data
|
||||
in a Work;
|
||||
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||
European Parliament and of the Council of 11 March 1996 on the legal
|
||||
protection of databases, and under any national implementation
|
||||
thereof, including any amended or successor version of such
|
||||
directive); and
|
||||
vii. other similar, equivalent or corresponding rights throughout the
|
||||
world based on applicable law or treaty, and any national
|
||||
implementations thereof.
|
||||
|
||||
2. Waiver. To the greatest extent permitted by, but not in contravention
|
||||
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
||||
irrevocably and unconditionally waives, abandons, and surrenders all of
|
||||
Affirmer's Copyright and Related Rights and associated claims and causes
|
||||
of action, whether now known or unknown (including existing as well as
|
||||
future claims and causes of action), in the Work (i) in all territories
|
||||
worldwide, (ii) for the maximum duration provided by applicable law or
|
||||
treaty (including future time extensions), (iii) in any current or future
|
||||
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
||||
including without limitation commercial, advertising or promotional
|
||||
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
||||
member of the public at large and to the detriment of Affirmer's heirs and
|
||||
successors, fully intending that such Waiver shall not be subject to
|
||||
revocation, rescission, cancellation, termination, or any other legal or
|
||||
equitable action to disrupt the quiet enjoyment of the Work by the public
|
||||
as contemplated by Affirmer's express Statement of Purpose.
|
||||
|
||||
3. Public License Fallback. Should any part of the Waiver for any reason
|
||||
be judged legally invalid or ineffective under applicable law, then the
|
||||
Waiver shall be preserved to the maximum extent permitted taking into
|
||||
account Affirmer's express Statement of Purpose. In addition, to the
|
||||
extent the Waiver is so judged Affirmer hereby grants to each affected
|
||||
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
||||
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
||||
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
||||
maximum duration provided by applicable law or treaty (including future
|
||||
time extensions), (iii) in any current or future medium and for any number
|
||||
of copies, and (iv) for any purpose whatsoever, including without
|
||||
limitation commercial, advertising or promotional purposes (the
|
||||
"License"). The License shall be deemed effective as of the date CC0 was
|
||||
applied by Affirmer to the Work. Should any part of the License for any
|
||||
reason be judged legally invalid or ineffective under applicable law, such
|
||||
partial invalidity or ineffectiveness shall not invalidate the remainder
|
||||
of the License, and in such case Affirmer hereby affirms that he or she
|
||||
will not (i) exercise any of his or her remaining Copyright and Related
|
||||
Rights in the Work or (ii) assert any associated claims and causes of
|
||||
action with respect to the Work, in either case contrary to Affirmer's
|
||||
express Statement of Purpose.
|
||||
|
||||
4. Limitations and Disclaimers.
|
||||
|
||||
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||
surrendered, licensed or otherwise affected by this document.
|
||||
b. Affirmer offers the Work as-is and makes no representations or
|
||||
warranties of any kind concerning the Work, express, implied,
|
||||
statutory or otherwise, including without limitation warranties of
|
||||
title, merchantability, fitness for a particular purpose, non
|
||||
infringement, or the absence of latent or other defects, accuracy, or
|
||||
the present or absence of errors, whether or not discoverable, all to
|
||||
the greatest extent permissible under applicable law.
|
||||
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||
that may apply to the Work or any use thereof, including without
|
||||
limitation any person's Copyright and Related Rights in the Work.
|
||||
Further, Affirmer disclaims responsibility for obtaining any necessary
|
||||
consents, permissions or other rights required for any use of the
|
||||
Work.
|
||||
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||
party to this document and has no duty or obligation with respect to
|
||||
this CC0 or use of the Work.
|
||||
63
README.md
Normal file
63
README.md
Normal file
@@ -0,0 +1,63 @@
|
||||
# Nice Nginx Error Page
|
||||
|
||||
This is a nicer error page for Nginx.
|
||||
|
||||
## Installation
|
||||
|
||||
Copy `templates/custom-error-page` folder in your web root folder, for example `/usr/share/nginx/html`.
|
||||
|
||||
Copy `config/custom-error-page` folder into your nginx config directory, for example `/etc/nginx/conf.d/`.
|
||||
|
||||
Edit `custom-error-page/http-statuses.conf` so the `root` values point to the correct folder on your server.
|
||||
|
||||
In your main nginx config file, include `custom-error-page/http-statuses.conf` outside the server block, like this:
|
||||
|
||||
```
|
||||
include /etc/nginx/conf.d/custom-error-page/http-status.conf;
|
||||
# ^ Add this line
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name localhost;
|
||||
# Your server configs here
|
||||
}
|
||||
```
|
||||
|
||||
In your nginx config file, include `custom-error-page/error-page.conf` inside your server block, like this:
|
||||
|
||||
```
|
||||
include /etc/nginx/conf.d/custom-error-page/http-statuses.conf;
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name localhost;
|
||||
|
||||
include /etc/nginx/conf.d/custom-error-page/error-page.conf;
|
||||
# ^ Add this line
|
||||
|
||||
# Your server configs here
|
||||
}
|
||||
```
|
||||
|
||||
Feel free to modify the error template to your liking!
|
||||
|
||||
## FAQ
|
||||
|
||||
### I'm using Nginx with fastcgi_pass or proxy_pass and I see an error page from the upstream instead of the custom one
|
||||
|
||||
By default, Nginx will use the error pages from upstream if they are available. Nginx will only show it's own error pages if it can't connect to the upstream server. For example in case of timeout or if the upstream is down. You can override this behavior by setting `fastcgi_intercept_errors on;` or
|
||||
`proxy_intercept_errors on;`.
|
||||
|
||||
### I'm using intercept_errors but I would like to still show the custom 404 from my application server.
|
||||
|
||||
You can accomplish this by removing `404` from the list of statuses in `error_page` directive, in the file `custom-error-page/error-page.conf`. TODO: check if this actually works.
|
||||
|
||||
## Thanks
|
||||
|
||||
I would like to thank the article [One NGINX error page to rule them all](https://blog.adriaan.io/one-nginx-error-page-to-rule-them-all.html) for inspiration. Using Server Side Includes drastically cuts down the number of required templates.
|
||||
|
||||
## License
|
||||
|
||||
CC0-1.0
|
||||
18
config/custom-error-page/error-page.conf
Normal file
18
config/custom-error-page/error-page.conf
Normal file
@@ -0,0 +1,18 @@
|
||||
location /custom-error-page.html {
|
||||
ssi on;
|
||||
internal;
|
||||
auth_basic off;
|
||||
root /usr/share/nginx/html/custom-error-page/;
|
||||
}
|
||||
|
||||
location /custom-error-page.css {
|
||||
auth_basic off;
|
||||
root /usr/share/nginx/html/custom-error-page/;
|
||||
}
|
||||
|
||||
location /inter-roman-var.woff2 {
|
||||
auth_basic off;
|
||||
root /usr/share/nginx/html/custom-error-page/;
|
||||
}
|
||||
|
||||
error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 421 422 423 424 425 426 428 429 431 451 494 495 496 497 500 501 502 503 504 505 506 507 508 510 511 /custom-error-page.html;
|
||||
47
config/custom-error-page/http-statuses.conf
Normal file
47
config/custom-error-page/http-statuses.conf
Normal file
@@ -0,0 +1,47 @@
|
||||
map $status $status_text {
|
||||
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';
|
||||
418 'I\'m a teapot';
|
||||
421 'Misdirected Request';
|
||||
422 'Unprocessable Entity';
|
||||
423 'Locked';
|
||||
424 'Failed Dependency';
|
||||
425 'Too Early';
|
||||
426 'Upgrade Required';
|
||||
428 'Precondition Required';
|
||||
429 'Too Many Requests';
|
||||
431 'Request Header Fields Too Large';
|
||||
451 'Unavailable For Legal Reasons';
|
||||
494 'Request header too large';
|
||||
495 'SSL Certificate Error';
|
||||
496 'SSL Certificate Required';
|
||||
497 'HTTP Request Sent to HTTPS Port';
|
||||
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';
|
||||
default 'Something went wrong';
|
||||
}
|
||||
184
templates/custom-error-page/custom-error-page.css
Normal file
184
templates/custom-error-page/custom-error-page.css
Normal file
@@ -0,0 +1,184 @@
|
||||
/*! minireset.css v0.0.6 | MIT License | github.com/jgthms/minireset.css */
|
||||
html,body,p,ol,ul,li,dl,dt,dd,blockquote,figure,fieldset,legend,textarea,pre,iframe,hr,h1,h2,h3,h4,h5,h6{margin:0;padding:0}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal}ul{list-style:none}button,input,select{margin:0}html{box-sizing:border-box}*,*::before,*::after{box-sizing:inherit}img,video{height:auto;max-width:100%}iframe{border:0}table{border-collapse:collapse;border-spacing:0}td,th{padding:0}
|
||||
|
||||
@font-face {
|
||||
font-family: "Inter var";
|
||||
font-weight: 100 900;
|
||||
font-display: swap;
|
||||
font-style: normal;
|
||||
font-named-instance: "Regular";
|
||||
src: url("./inter-roman-var.woff2?v=3.19") format("woff2");
|
||||
}
|
||||
|
||||
html {
|
||||
font-family: "Inter var", sans-serif;
|
||||
}
|
||||
.container {
|
||||
min-height: 100vh;
|
||||
background-color: white;
|
||||
display: flex;
|
||||
}
|
||||
@media (max-width: 1023px) {
|
||||
.container {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
.left,
|
||||
.right {
|
||||
width: 50%;
|
||||
}
|
||||
@media (max-width: 1023px) {
|
||||
.left,
|
||||
.right {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
.left {
|
||||
background-color: #f44336;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
@media (max-width: 1023px) {
|
||||
.left svg {
|
||||
min-height: 200px;
|
||||
}
|
||||
}
|
||||
.left svg {
|
||||
width: 300px;
|
||||
height: auto;
|
||||
opacity: 0.3;
|
||||
margin-right: 40px;
|
||||
margin-left: 40px;
|
||||
}
|
||||
@media (max-width: 1023px) {
|
||||
.left svg {
|
||||
width: 100px;
|
||||
}
|
||||
}
|
||||
.right {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.text-container {
|
||||
width: 500px;
|
||||
margin-right: 40px;
|
||||
margin-left: 40px;
|
||||
margin-top: 40px;
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
.text-container *:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.code {
|
||||
font-size: 75px;
|
||||
margin-bottom: 40px;
|
||||
font-weight: 700;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
/* https://seek-oss.github.io/capsize/ */
|
||||
|
||||
.code::before {
|
||||
content: "";
|
||||
margin-bottom: -0.2597em;
|
||||
display: table;
|
||||
}
|
||||
|
||||
.code::after {
|
||||
content: "";
|
||||
margin-top: -0.287em;
|
||||
display: table;
|
||||
}
|
||||
|
||||
@media (max-width: 1300px) {
|
||||
.code {
|
||||
font-size: 75px;
|
||||
}
|
||||
}
|
||||
@media (max-width: 1023px) {
|
||||
.code {
|
||||
font-size: 50px;
|
||||
}
|
||||
}
|
||||
.status {
|
||||
font-size: 38px;
|
||||
margin-bottom: 40px;
|
||||
font-weight: 500;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.status::before {
|
||||
content: "";
|
||||
margin-bottom: -0.2758em;
|
||||
display: table;
|
||||
}
|
||||
|
||||
.status::after {
|
||||
content: "";
|
||||
margin-top: -0.3031em;
|
||||
display: table;
|
||||
}
|
||||
|
||||
@media (max-width: 1023px) {
|
||||
.status {
|
||||
font-size: 25px;
|
||||
}
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: 18px;
|
||||
line-height: 1.5;
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
|
||||
/* https://seek-oss.github.io/capsize/ */
|
||||
|
||||
.description::before {
|
||||
content: "";
|
||||
margin-bottom: -0.3752em;
|
||||
display: table;
|
||||
}
|
||||
|
||||
.description::after {
|
||||
content: "";
|
||||
margin-top: -0.4026em;
|
||||
display: table;
|
||||
}
|
||||
|
||||
.footer {
|
||||
font-size: 16px;
|
||||
margin-bottom: 40px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
/* https://seek-oss.github.io/capsize/ */
|
||||
|
||||
.footer::before {
|
||||
content: "";
|
||||
margin-bottom: -0.3613em;
|
||||
display: table;
|
||||
}
|
||||
|
||||
.footer::after {
|
||||
content: "";
|
||||
margin-top: -0.3887em;
|
||||
display: table;
|
||||
}
|
||||
.button-container {
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
.button {
|
||||
all: unset;
|
||||
display: inline-block;
|
||||
background-color: #f44336;
|
||||
color: white;
|
||||
font-weight: 500;
|
||||
border-radius: 3px;
|
||||
padding-top: 12px;
|
||||
padding-bottom: 12px;
|
||||
padding-left: 15px;
|
||||
padding-right: 15px;
|
||||
cursor: pointer;
|
||||
}
|
||||
61
templates/custom-error-page/custom-error-page.html
Normal file
61
templates/custom-error-page/custom-error-page.html
Normal file
@@ -0,0 +1,61 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title> <!--# echo var="status" default="" --> – <!--# echo var="status_text" default="Something went wrong" --> </title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="stylesheet" href="./custom-error-page.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="left">
|
||||
<svg
|
||||
width="300"
|
||||
height="300"
|
||||
viewBox="0 0 300 300"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M153.01 33.2a6 6 0 0 1 2.18 2.18l129.7 223.61a6 6 0 0 1-5.19 9.01H20.3a6 6 0 0 1-5.2-9.01L144.8 35.38a6 6 0 0 1 8.21-2.18ZM150.02 204a14.01 14.01 0 1 0-.02 28.02 14.01 14.01 0 0 0 .02-28.02Zm4.8-89h-9.65a6 6 0 0 0-6 6.17l1.5 52a6 6 0 0 0 6 5.83h6.67a6 6 0 0 0 6-5.83l1.48-52a6 6 0 0 0-6-6.17Z"
|
||||
fill="#000"
|
||||
fill-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="right">
|
||||
<div class="text-container">
|
||||
<h1 class="code">
|
||||
<!--# echo var="status" -->
|
||||
</h1>
|
||||
<div class="status">
|
||||
<!--# echo var="status_text" default="Something went wrong" -->
|
||||
</div>
|
||||
<div class="description">
|
||||
<!--# if expr="$status = 404" -->
|
||||
The page you were looking for may have been deleted or
|
||||
moved.
|
||||
<!--# elif expr="$status = /4\d\d/" -->
|
||||
Your browser sent a request that the server was unable
|
||||
to process.
|
||||
<!--# elif expr="$status = /5\d\d/" -->
|
||||
The server encountered an error and could not complete
|
||||
your request. Please try again later.
|
||||
<!--# else -->
|
||||
Something went wrong while trying to display this page.
|
||||
Please try again later.
|
||||
<!--# endif -->
|
||||
</div>
|
||||
<!--# if expr="$status = 404" -->
|
||||
<div class="button-container">
|
||||
<a href="/" class="button">Back to home</a>
|
||||
</div>
|
||||
<!--# endif -->
|
||||
<div class="footer">
|
||||
Nginx at <!--# echo var="host" default="localhost" -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
BIN
templates/custom-error-page/inter-roman-var.woff2
Normal file
BIN
templates/custom-error-page/inter-roman-var.woff2
Normal file
Binary file not shown.
Reference in New Issue
Block a user