1

I'm having redirection issues when I try to access DomainB on my browser, for some reason I get redirected to DomainA, what could be going on here?

(This is my sites-available folder)

Btw I removed DomainB from sites-enables, and I still get the same redirection... could it be a DNS issue and not an nginx issue?

##
## /etc/nginx/sites-available/DomainC
##

server {
    listen 80;
    server_name domainC.com www.domainC.com;
    return 301 https://domainA.com/blog$request_uri;
}

##
## /etc/nginx/sites-available/DomainA
##

server {
    listen 80;
    server_name domainA.com www.domainA.com;
    return 301 https://domainA.com$request_uri;
}

server {
    listen 443 ssl;
    server_name www.domainA.com;
    include domainA.ssl.conf;
    return 301 https://domainA.com$request_uri;
}

server {
    server_name domainA.com;
    root /var/www/domainA.com;
    listen 443 ssl;
    index index.html;
    autoindex off;
    include common.conf;
    include domainA.ssl.conf;
}

##
## /etc/nginx/sites-available/DomainB
##

server {
    listen 80;
    server_name domainB.cl;
    return 301 http://www.domainB.cl$request_uri;
}

 server {
    listen 80;
    server_name www.domainB.cl;
    root /var/www/domainB.cl;
    index index.html;
}

EDIT: I think that it may be related to the fact that if for some reason I go to http://vps_ip/ (eg 192.123.123.123), I also get redirected to https://DomainA.com/blog/

Mr.Gando
  • 111
  • 1
  • 5

1 Answers1

1

You are redirecting requests for http://domainB.cl to http://www.domainB.cl. As you have only configured

server_name domainB.cl;

and not

server_name domainB.cl www.domainB.cl;

, nginx doesn't know which virtual host it should use. Therefore it redirects the request to the default one in your configuration, which is the one for domainA.com. The same applies if you remove the vhost from sites-enabled: nginx uses the default vhost.

To get this solved, you will have to add a vhost for www.domainB.cl.

etagenklo
  • 5,834
  • 1
  • 27
  • 32
  • I was missing that part of the config, just edited my code and pasted it. I'm almost certain that the problem lies in domainA first redirection, that seems to be redirecting all of my port 80 traffic to `https://domainA.com$request_uri` . It should only perform that redirection if the host in question is actually domainA (right now even `http://vps_ip` redirects to `https://domainA.com$request_uri` – Mr.Gando Jul 20 '13 at 16:49
  • Ok, fould the problem. There was a CNAME like * -> domainA.com , replaced that for www domainA.com (did the same for some other domains) it's working fine now. Thanks! – Mr.Gando Jul 20 '13 at 17:06
  • Ok, I couldn't see this from your nginx configuration ;) – etagenklo Jul 20 '13 at 17:33