Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

domain.com and b.domain.com. Both subdomains are on different servers. I'm using nginx as my webserver. What must I change to nginx.conf to redirect all traffic from a.domain.com to b.domain.com?

Thank you!

share|improve this question

This question could stand to provide more details. Can we assume nginx is the httpd on both servers? What kind of configuration is already in place?

This howto gives a hint which leads me to suggest this:

On server a.domain.com:

server {
    listen       80;
    server_name  a.domain.com;
    rewrite   ^  http://b.domain.com$request_uri?;
}

On server b.domain.com:

server {
    listen       80;
    server_name  b.domain.com;
    // Remaining vhost configuration
}
share|improve this answer

pjmorse's answer is good (so I upvoted it), but I use a slightly different scheme on a.domain:

server {
  server_name a.domain.com c.domain.com d.domain.com;    # you can serve any number of redirects from here...
  listen 80;
  rewrite (.*) http://b.domain.com$1 permanent;
}

This returns a HTTP 301 return code (moved permanently) instead of the 307 that some webservers may return.

share|improve this answer
server {
    server_name
        a.domain.com
    ;
    return 301 http://b.domain.com$request_uri;
}

you could set up a permanent redirect from one domain to another.

share|improve this answer

Your Answer

 
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 or ask your own question.