I was asking me if I can redirect all my system request from server1.com/service1 to server2.com/service1..

This is my situation. I have a web application in my main server (mainserver.com), Then I have 3 servers with a serie of rest services, by example:

mainserver.com -> web application


It's very common that serviceservers are down, then we have to change the service URLs to another server and restar our app (We can't change the app behaivour)

Well, I was thinking about something like host redirections or something that works like these, but only in URL level, no host level.

  • Does the "web application" run on "mainserver.com" and make requests to "serviceserverX.com" or does the request for "serviceserverX.com" come a client device? If "mainserver.com" is making the request you can edit /etc/hosts which should be read per request. – Tigger Aug 18 '17 at 10:44

You can use Nginx for that: first you have to configure and upstream:

upstream web {
  server serviceserver1.com
  server serviceserver2.com
  server serviceserver3.com

Then what you're looking for are: proxy_next_upstream and proxy_connect_timeout.

Try this:

location / {
        proxy_pass              $scheme://web;
        proxy_redirect          off;
        proxy_next_upstream     error timeout invalid_header http_500;
        proxy_connect_timeout   2;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.