Nginx 503 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 Share Contents Contents We hope nginx default error page location you find this tutorial helpful. In addition to guides like this one, we provide simple nginx maintenance page with images cloud infrastructure for developers. Learn more → 9 How To Configure Nginx to Use Custom Error Pages on Ubuntu 14.04 Posted Jun
Nginx Error_page
5, 2015 81.6k views Nginx Ubuntu Introduction Nginx is a high performance web server capable of serving content with flexibility and power. When designing your web pages, it is often helpful to customize every piece of
Nginx Maintenance Page Try_files
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 of this type by following along with our initial set up guide for Ubuntu 14.04. nginx error page 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 pages that we can serve when client requests result in different errors. Configuring Nginx to Use your Error Pages Now, we just need to tell Nginx that it should be utihere for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting
Nginx Custom Error Page
ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join nginx 503 service unavailable the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a nginx custom error page not working minute: Sign up How can I setup a custom 503 error page in NGINX? up vote 9 down vote favorite 8 I learned how to get NGINX to return 503 customer error pages, but I cannot find out how to do https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-to-use-custom-error-pages-on-ubuntu-14-04 the following: Sample config file: location / { root www; index index.php; try_files /503.html =503; } error_page 503 /503.html; location = /503.html { root www; } As you can see, according to the code above, if a page called 503.html is found in my root directory, the site will return this page to the user. But it seems that although the code above works when someone simply visits my site typing http://www.example.com it does not trap requests like: http://www.example.com/profile.php With my code, http://stackoverflow.com/questions/5600448/how-can-i-setup-a-custom-503-error-page-in-nginx the user can still see the profile page or any other pages besides index.php. The question: How do I trap requests to all pages in my site and forward them to 503.html whenever 503.html is present in my root folder? nginx share|improve this question edited May 7 '15 at 9:40 wpp 3,30521542 asked Apr 8 '11 at 20:29 Vini 52721333 add a comment| 3 Answers 3 active oldest votes up vote 6 down vote Updated: changed "if -f" to "try_files". Try this: server { listen 80; server_name mysite.com; root /var/www/mysite.com/; location / { try_files /maintenance.html $uri $uri/ @maintenance; # When maintenance ends, just mv maintenance.html from $root ... # the rest of your config goes here } location @maintenance { return 503; } } More info: http://serverfault.com/questions/18994/nginx-best-practices http://wiki.nginx.org/HttpCoreModule#try_files share|improve this answer edited Apr 10 '11 at 3:02 answered Apr 9 '11 at 11:45 Ken Cochrane 31.2k73349 try_files is the best practice. Also, it is not missing. It's just incomplete. –Vini Apr 9 '11 at 19:49 @Vini what's the difference between not missing and incomplete, to me it is the same thing. I updated the example to include try_files instead of if -f. Hope that helps. –Ken Cochrane Apr 9 '11 at 21:32 Thank you Ken. By the way, what does $uri do? I see it twice in a row. –Vini Apr 10 '11 at 2:40 @Vini $uri is equal to current URI in the request (without argument
you may need to put up a "maintenance" page and send back "HTTP 503 Service Unavailable" for all incoming https://aaronparecki.com/2014/09/03/28/custom-json-503-error-page-nginx-http-content-type-headers HTTP requests. For some reason, all the existing docs I found online were either too complicated or did not handle this properly. Here is a simple configuration block that will do the following: Return a header of HTTP 503 Service Unavailable Set the content-type to application/json Send a JSON file that you create as the response error page body http { server { listen 80; server_name example.com; root /usr/local/nginx/html; location / { try_files $uri =503; } error_page 503 /maintenance.json; } } In the directory specified by root, create a maintenance.json file containing something like the following: { "code": 503, "error": "temporarily_unavailable", "error_description": "Sorry, the service is temporarily unavailable" } After reloading nginx (something like /usr/local/nginx/sbin/nginx nginx maintenance page -s reload) all future requests to this host will return a response like below: HTTP/1.1 503 Service Temporarily Unavailable Server: nginx/1.4.7 Date: Thu, 04 Sep 2014 07:07:35 GMT Content-Type: application/json Content-Length: 128 Connection: keep-alive { "code": 503, "error": "temporarily_unavailable", "error_description": "Sorry, the service is temporarily unavailable" } #nginx #tutorial Wed, Sep 3, 2014 11:58pm -07:00 1 mention Other Mentions bear bear.im IndieWeb Note 1 This is a test article! 503 error page test known page for leo Fri, Apr 25, 2014 5:00pm -07:00 Posted in /articles Hi, I'm Aaron Parecki, co-founder of IndieWebCamp. I maintain oauth.net, write about OAuth, and am the editor of the W3C Webmention and Micropub specifications. I've been tracking my location since 2008, and write down everything I eat and drink. I've spoken at conferences around the world about owning your data, OAuth, quantified self, and explained why R is a vowel. IndieWebCamp Founder W3C Editor These are a few of my favorite things. All Articles Bookmarks Notes Photos Sleep Travel Contact © 1999-2016