Nginx Custom 500 Error Page
Contents |
In submit Tutorials Questions Projects Meetups Main Site logo-horizontal DigitalOcean Community Menu Tutorials Questions Projects Meetups Main Site Sign Up Log In submit View All Results By: Justin Ellingwood Subscribe Subscribed nginx error_page Share Contents Contents We hope you find this tutorial helpful. In addition to guides nginx custom error page not working like this one, we provide simple cloud infrastructure for developers. Learn more → 9 How To Configure Nginx to Use nginx error page Custom Error Pages on Ubuntu 14.04 Posted Jun 5, 2015 81.7k views Nginx Ubuntu Introduction Nginx is a high performance web server capable of serving content with flexibility and power. When designing your web
Nginx Custom 404
pages, it is often helpful to customize every piece of content that your users will see. This includes error pages for when they request content that is not available. In this guide, we'll demonstrate how to configure Nginx to use custom error pages on Ubuntu 14.04. Prerequisites To get started on with this guide, you will need a non-root user with sudo privileges. You can set up a user nginx dynamic error page of this type by following along with our initial set up guide for Ubuntu 14.04. You will also need to have Nginx installed on your system. Learn how to set this up by following this guide. When you have completed the above steps, continue with this guide. Creating Your Custom Error Pages We will create a few custom error pages for demonstration purposes, but your custom pages will obviously be different. We will put our custom error pages in the /usr/share/nginx/html directory where Ubuntu's Nginx sets its default document root. We'll make a page for 404 errors called custom_404.html and one for general 500-level errors called custom_50x.html. You can use the following lines if you are just testing. Otherwise, put your own content in these locations:
- echo "
Error 404: Not found :-(
" | sudo tee /usr/share/nginx/html/custom_404.html - echo "
I have no idea where that file is, sorry. Are you sure you typed in the correct URL?
" | sudo tee -a /usr/share/nginx/html/custom_404.html - echo "
Oops! Something went wrong...
" | sudo tee /usr/share/nginx/html/custom_50x.html - echo "
We seem to be having some technical difficulties. Hang tight.
" | sudo tee -a /usr/share/nginx/html/custom_50x.html We now have two custom error pagnginx, sysadmin I was working with our customer Paper Source to setup a 500 error page that looked like the rest of the site when I ran into something interesting. I went through the nginx configuration nginx error page redirect and added this line to allow for a custom 500 error page just like I
Nginx 404 Error
had done for the custom 404 error page.error_page 500 = /cgi-bin/paper/500.html; What I noticed when I forced the site to create an
Nginx Default 404 Page
Internal Server Error was that I was still getting the ugly normal Apache version of the 500 error page. It seemed like nginx was ignoring the error_page directive. I did some searching and found out that you https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-to-use-custom-error-pages-on-ubuntu-14-04 have to use the proxy_intercept_errors directive.proxy_intercept_errors on; This directive allows nginx to recognize the 500 error code being returned from Apache and run its own directives to display the right page. 2 comments: val said... Thank you for figuring this out! I was hours and what seems to be hundreds of nginx restarts before finding this! January 2, 2014 at 8:17:00 PM EST Ben said... Thank you so much for finding that! I was about http://blog.endpoint.com/2013/06/custom-500-error-page-while-using-nginx.html to go crazy trying to figure out what was happening lol February 17, 2015 at 2:44:00 PM EST Post a Comment Newer Post Older Post Subscribe to: Post Comments (Atom) Archive ► 2016 (76) ► October (6) ► September (5) ► August (5) ► July (10) ► June (6) ► May (6) ► April (9) ► March (9) ► February (8) ► January (12) ► 2015 (122) ► December (8) ► November (10) ► October (8) ► September (7) ► August (9) ► July (8) ► June (7) ► May (5) ► April (17) ► March (13) ► February (13) ► January (17) ► 2014 (157) ► December (4) ► November (13) ► October (10) ► September (12) ► August (6) ► July (13) ► June (19) ► May (11) ► April (22) ► March (20) ► February (17) ► January (10) ▼ 2013 (164) ► December (14) ► November (23) ► October (11) ► September (11) ► August (9) ► July (15) ▼ June (16) Rails transposing day and month after upgrading Ru... Custom 500 error page while using nginx proxying Debugging obscure Postgres problems with strace Spree's New Release Policy Making use of a Unix Pipe Railsbridge NYC Installing PostgreSQL without Root Converting root filesystem from ext3 to ext4 on Ce... PostgreSQL Functional Indexes Creating custom button graphics in
pages. In https://marekbosman.com/site/custom-error-pages-for-nginx/ order to so, a minor change to the config https://www.garron.me/en/go2linux/nginx-create-custom-404-page-not-found-error-page.html file is needed. You can either use the default nginx config (/etc/nginx/nginx.conf) or the config of a single site (/etc/nginx/sites-enabled/example.com). I prefer the latter. Add the following lines to the server block: # Custom error pages error_page 401 /error/401/index.html; error_page 403 /error/403/index.html; error_page 404 /error/404/index.html; error_page 405 /error/405/index.html; error_page 500 501 502 503 504 /error/5xx/index.html; location ^~ /error/ nginx error page { internal; } You only need to add the definitions for the HTTP status codes you want to support. If you don’t need a custom error page for 401 errors, just leave it out from the config file and nginx will serve the default response. In the example above, all error pages will be served from the directory error within the document root of the current site. If you want to serve the files from a common directory for all configured site then you need something like this: location ^~ /error/ { internal; root /path/to/common/error-files; } In both cases you’ll notice the line that says internal. This prevents visitors to fetch the error pages directly. Save the files and reload the nginx config. Now your own custom erro
page not found error page Written by Guillermo Garron Date: 2010-12-06 10:50:30 00:00 Introduction I'm working with Nginx since more than a year ago, it is an extremely fast web server, specially to work in front of Apache serving static content. Well, if you need to customize your 404 (file not found) error page in Nginx, you are in the right place. First what is a 404 error, from Wikipedia: The 404 or Not Found error message is a HTTP standard response code indicating that the client was able to communicate with the server, but the server could not find what was requested. 404 errors should not be confused with "server not found" or similar errors, in which a connection to the destination server could not be made at all. A 404 error indicates that the requested resource may be available again in the future Creating your own 404 error page In the event some of your users get a 404 (page not found) error, it is better if you provide him with a good page, so he can stay at your site. Some simple example can be this one:
Page Not Found Page Not Found
We're very sorry to inform you that the page you are looking for could not be found, please accept our apologies, and follow one of the following options
Configure Nginx to use your custom page Now to make Nginx use your custom page instead of the default one, edit the file nginx.conf which could be at /etc/nginx/ Inside the server section, add: error_page 404 /404.html; It is a good idea, to block the access to that page, unless there is an error, so add this below the above line: location /404.html { internal; } S