GithubHelp home page GithubHelp logo

joppuyo / nice-nginx-error-page Goto Github PK

View Code? Open in Web Editor NEW
19.0 4.0 2.0 402 KB

What if your application could look nice even when it's crashing?

License: MIT License

CSS 59.21% HTML 40.79%
nginx html css http error-page error-messages

nice-nginx-error-page's Introduction

Nice Nginx Error Page

REUSE status

What if your application could look nice even when it's crashing? Try this custom error page for Nginx.

Preview

Installation

Copy templates/custom-error-page folder in your web root folder, for example /usr/share/nginx/html/custom-error-page.

Copy config/custom-error-page folder into your nginx config directory, for example /etc/nginx/conf.d/custom-error-page.

Edit custom-error-page/error-page.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 inside the http block, outside the server block, like this:

include /etc/nginx/conf.d/custom-error-page/http-statuses.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
}

Restart Nginx and you're done.

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 xxx_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 for serving as inspiration. Using Server Side Includes drastically cuts down the number of required templates.

License

MIT.

For detailed license information, see the individual file headers and .reuse/dep5.

nice-nginx-error-page's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nice-nginx-error-page's Issues

Add minified version

Add minified CSS files, I think HTML should remain un-minified to improve readability.

Use system fonts

Use system fonts and not custom web fonts, preferably metrically compatible with Helvetica/Helvetica Neue so capsize works.

This should improve performance and remove the requirement for extra assets.

Set up releases

Set up releases to generate optimized files and start versioning the project.

Use purgeCSS

Using purgeCSS would get rid of unused css reset classes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.