WebFaction
Community site: login faq

I'm working on a site for a client. Right now, the new version is not ready to roll, but the old one (hosted elsewhere and not my work) often goes down without warning. Here's what I'd like to do:

  1. Point the domain to the webfaction account I have to host the new version.
  2. Set up a custom app listening on port to respond to requests to that domain; install Nginx for this app.
  3. Either set an upstream with the old site as the 1st server, and a static app on my webfaction account, with a page apologizing for the downtime and giving some light functionality in the meantime, as the 2nd server, perhaps marked "backup"?

With the thinking that if the existing site is up, traffic will be routed there. If it's not, it falls back to my static site.

I've tried a few things to get this going but I've had no luck. Can anyone advise how to handle such a situation, if there's a good way to do it?

asked 29 Aug '12, 17:30

Dave Stevens
812612
accept rate: 50%

I don't understand what mechanism you're using for the fallback (ie, the part that decides where to send the requrest).

Or was that your question?

(29 Aug '12, 19:22) seanf

Yes and no - I wasn't entirely sure how the upstream directive worked, I thought if I set the other site as the first listed server and then the fallback static site as the 2nd listed server with "backup", that would work - but for whatever reason (most likely my fault) it didn't. Got it working by doing this:

http {
    server {
       listen 12345; #Port that my custom app was assigned
       server_name mydomain.com;

       location / {
         proxy_intercept_errors on;
         error_page 400 403 502 503 504 = @fallback;
         proxy_pass http://the_old_site_domain.com;      
       }

       location @fallback {
         proxy_pass http://myfallback.domain.com;
       }
    }
}

The fallback domain is a static apache site, with a single index.html file at the root, and an .htaccess with: ErrorDocument 404 /index.html

Meaning that when the main (old) site is down, the fallback is shown, and all attempted paths just show the page that apologises for the downtime and gives some limited functionality.

(30 Aug '12, 10:58) Dave Stevens

Very interesting - thanks for sharing that! You might want to post that as an answer to your own question, using the answer form at the bottom of this page :)

(30 Aug '12, 12:31) seanf

So I ended up doing this - reposted as an answer to hopefully help others:

http {
  server {
     listen 12345; #Port that my custom app was assigned
     server_name mydomain.com;

     location / {
       proxy_intercept_errors on;
       error_page 400 403 502 503 504 = @fallback;
       proxy_pass http://the_old_site_domain.com;      
     }

     location @fallback {
       proxy_pass http://myfallback.domain.com;
     }
  }
}

The fallback domain is a static apache site, with a single index.html file at the root, and an .htaccess with: ErrorDocument 404 /index.html

Meaning that when the main (old) site is down, the fallback is shown, and all attempted paths just show the page that apologises for the downtime and gives some limited functionality.

permanent link

answered 30 Aug '12, 15:00

Dave Stevens
812612
accept rate: 50%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×186

question asked: 29 Aug '12, 17:30

question was seen: 10,114 times

last updated: 30 Aug '12, 15:00

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2020 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM