3

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!

4

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.

| improve this answer | |
3

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
}
| improve this answer | |
  • The documentation on the link suggests that this is wrong way to do it and offers a right one. – Okneloper Oct 19 '16 at 20:03
  • This answer is six years old, and it is entirely likely that the right way to do it has changed. Feel free to provide a new answer. – pjmorse Oct 20 '16 at 13:01
1
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.

| improve this answer | |

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.