Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

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

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.