Nginx Custom 503 Error Page
Contents |
how to create a custom http 503 maintenance page under Lighttpd or Apache web server. How do I create a nginx default error page location custom Nginx web server maintenance page?
HTTP error code 503 informsNginx Error_page
clients and search engines that the website is temporary out of service because it is nginx maintenance page with images overloaded or down for maintenance. Generally, this is a temporary state. Step #1: Create a Custom 503 Service Unavailable HTML PageFirst, you need to
Nginx Error Page
create a custom http 503 page at /usr/local/nginx/html/error503.html:
503 Service Unavailable
Our apologies for the temporary inconvenience. The requested URL generated 503 "Service Unavailable" error due to overloading or maintenance of the server. Step #2: Update Nginx ConfigurationEdit /usr/local/nginx/config/nginx.conf, enter:# vi /usr/local/nginx/config/nginx.confUpdate nginx maintenance page try_files configuration as follows: if (-f $document_root/error503.html) { return 503; } error_page 503 @maintenance; location @maintenance { rewrite ^(.*)$ /error503.html break; }A complete config is as follows:server { access_log logs/example.com_access.log main; error_log logs/example.com_error.log info; index index.html; limit_conn gulag 50; listen xxx.yyy.zzz.www:80 default; root /usr/local/nginx/html; server_name example.com www.example.com; ## Only requests to our Host are allowed if ($host !~ ^(example.com|www.example.com)$ ) { return 444; } ## redirect www to nowww if ($host = 'www.example.com' ) { rewrite ^/(.*)$ http://example.com/$1 permanent; } # Only allow these request methods if ($request_method !~ ^(GET|HEAD|POST)$ ) { return 444; } location / { if (-f $document_root/error503.html) { return 503; } } # redirect server error pages to the static page /50x.html error_page 500 502 504 /50x.html; location = /50x.html { root html; } # error 403 error_page 403 /error403.html; location = /error403.html { root html; allow all;here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies
Nginx Custom Error Page
of this site About Us Learn more about Stack Overflow the company
Nginx 503 Error
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges nginx custom error page not working Ask Question x Dismiss Join 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 minute: http://www.cyberciti.biz/faq/custom-nginx-maintenance-page-with-http503/ 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 the following: Sample config file: location / { root www; index index.php; try_files /503.html =503; } error_page 503 /503.html; location = /503.html http://stackoverflow.com/questions/5600448/how-can-i-setup-a-custom-503-error-page-in-nginx { 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, 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; } }
Start here 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 http://serverfault.com/questions/140759/how-do-i-use-a-custom-503-error-page-with-nginx about hiring developers or posting ads with us Server Fault Questions Tags Users Badges Unanswered Ask Question _ Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute: Sign https://www.ruby-forum.com/topic/141251 up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top How do I use a custom 503 error page with Nginx? up vote 9 down error page vote favorite 4 I have implemented rate limiting with Nginx (which works excellently, by the way) and would like to display a custom 503 error page. I have followed examples on the web without luck. I am running a simple configuration that looks something like this: listen x.x.x.x:80 server_name something.com root /usr/local/www/something.com; error_page 503 /503.html; location / { limit_req zone=default burst=5 nodelay; proxy_pass http://mybackend; } The idea is that our rate limited users would be shown a special nginx maintenance page page explaining what was going on. The rate limiting is working, but the built-in 503 page is rendering. Any ideas? nginx share|improve this question asked May 11 '10 at 17:22 Michael Gorsuch 1,86511423 add a comment| 1 Answer 1 active oldest votes up vote 5 down vote accepted add location = /503.html { root /path/to/the/page; } share|improve this answer answered May 12 '10 at 14:09 edogawaconan 31114 Thanks! That was it! –Michael Gorsuch May 12 '10 at 19:02 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged nginx or ask your own question. asked 6 years ago viewed 3593 times active 6 years ago Related 0How to make nginx reverse proxy let 503 error pages pass through to client?1Trouble with nginx and serving from multiple directories under the same domain1How to create custom content for nginx error 502 page, keep origin url on browser1Can not change nginx 1.2.5 default website1'return 404;' does not respect custom error page setup in Nginx0Nginx custom 404 page results in 500 internal server error-1Nginx Custom Error Page not
Douglas A. Seifert (Guest) on 2008-02-03 00:31 I am trying to use a test for the existence of a file to return a error page with a 503 Temporarily Unavailable response code. My configuration is below. The problem is that it does not work. I can see the custom error page, but the HTTP status code is 200, not the desired 503. If I change the if directive to this: if (-f $document_root/system/maintenance.html) { rewrite ^(.*)$ /system/maintenance.html; # No last return 503; } I start getting a 503 HTTP status code, but the content is not my custom error page, but rather the default 503 response compiled into the nginx server. Am I doing something terribly wrong? I would really like to see my custom page with a real 503 HTTP status code. Thanks for any help, Douglas A. Seifert nginx.conf: -------------------------------------------------- # user and group to run as #user www www; # number of nginx workers worker_processes 6; # pid of nginx master process pid /usr/local/www/nginx.pid; # Number of worker connections. 1024 is a good default events { worker_connections 1024; } # start the http module where we config http access. http { # pull in mime-types. You can break out your config # into as many include's as you want to make it cleaner include /usr/local/nginx/conf/mime.types; # set a default type for the rare situation that # nothing matches from the mimie-type include default_type application/octet-stream; # configure log format log_format main '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; # main access log access_log /usr/local/www/log/nginx_access.log main; # main error log error_log /usr/local/www/log/nginx_error.log debug; # no sendfile on OSX sendfile on; # These are good default values. tcp_nopush on; tcp_nodelay off; # output compression saves bandwidth gzip on; gzip_http_version 1.0; gzip_comp_level 2; gzip_proxied any; gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; server { # port to listen on. Can also be set to an IP:PORT listen *:8080; # Set the max size for file uploads to 50Mb client_max_body_size 50M; # sets the domain[s] that this vhost server requests for server_name .foo.com *; # doc root root /usr/local/www/test; # vhost specific access log access_log /usr/local/www/log/nginx.vhost.access.log main; # this rewrites all the requests to the maintenance.html # page if it exists in the doc root. This is for capistrano's # d