10

I have got two servers (A and B) with NGINX. Server A is serving old site and server B is serving a new site. I've updated my DNS but it is quite slow: in my office I still see my old site:

subdomain.site.com

How can I redirect all requests from server A for this particular subdomain to server B?

Now they both are handled with this in NGINX:

server {
  listen 80;
  server_name subdomain.site.ru;
  root /var/www/subdomain/public;
  passenger_enabled on;
}

1 Answer 1

17

Since they're both using the same server_name, you can't do a simple redirection.

You can probably do some sort of proxy, though, along the lines of the following on the old server:

upstream newserver {
  server 172.16.0.1:80;  # this is new server, by IP address
}

server {
  listen 80;
  server_name subdomain.site.ru;
  location / {
    proxy_set_header Host $host;
    proxy_pass http://newserver;
  }
}

So, basically, configure the old server so that it will pass all requests to the new server. Of course, put in whatever configuration you'll need for client_max_body_size and all that.

2
  • How can this be done using SSL? Does the proxy machine need the ssl certificate as well as the upstream server?
    – earthmeLon
    Apr 22, 2013 at 8:39
  • @earthmeLon In the original question, this proxy was a temporary measure for the DNS update. In that case, both new and old servers would have the SSL certificate. In the case of the upstream, you can connect over SSL or over plain HTTP; since you control both boxes, it'd be up to your preference.
    – cjc
    Apr 22, 2013 at 14:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .