I am trying to configure nginx to respond to two domains: domain1.com
& domain2.com
yet if someone tries to access domain2.com
he will 301 redirected to domain1.com
(with the full request params), how can I do that? i am getting redirect loops all the time.
Asked
Active
Viewed 40 times
-1

Broshi
- 3,334
- 5
- 37
- 52
-
can you share your config? it should look like this ```server { server_name domain1.com www.domain1.com; rewrite ^ $scheme://www.domain2.com; }``` – Ereli Mar 13 '16 at 14:04
-
Thanks Ereli, already solved this issue! – Broshi Mar 13 '16 at 14:54
-
Your question is the same as [how to redirect www to no-www](http://stackoverflow.com/questions/7947030/nginx-no-www-to-www-and-www-to-no-www) (as www and no-www are 2 different domains). You haven't shown your existing config, which makes it somewhat impossible for anyone to say why you're getting a redirect loop. – AD7six Mar 13 '16 at 16:19
-
@AD7six i've published my config as an answer. – Broshi Mar 15 '16 at 15:59
1 Answers
0
Yes! managed to resolve it with two server
entries:
server {
listen 80;
server_name domain2.com www.domain2.com;
return 301 $scheme://domain1.com$request_uri;
}
server {
listen 80;
server_name domain1.com www.domain1.com;
# Root directory
root /home/myuser/sites/domain1.com/public;
index index.php index.html;
// rest of configs
}

Broshi
- 3,334
- 5
- 37
- 52