Page 1 of 1

Cloudfront error: alias root domain redirect to subdomain, wrong response header and SSL cert

Posted: Mon Jun 11, 2018 4:58 pm
by ouchdigital
Hey everyone,

I've nearly got AWS Cloudfront up and running with an Alias CNAME www. property. Everything is set-up and working, however the alias root - www.example.com - is redirecting to a completely different subdomain.

All internal pages such as www.example.com/page are resolving correctly, and it appears to only be the one page which doesn't like it.

After extensive trial and error I've isolated the issue to the response headers and the server which is sending back the subdomain other.example.com.

I believe this may be something to do with that subdomain's nginx.conf files being listed first in the /home/user/conf/web/ directory.

I'm also suspecting it's linked to the SSL certificates since the response header appears to be sending the subdomain's SSL certificate in response to the request.

Is there any way to force the location for the root alias only - www.example.com - to respond with the correct domain? Or to repair the nginx.conf file to send the correct domain in reponse?

Alias www domain was also added and removed and added to try to find the solution and it could be linked to that. Fresh certificates were created with restarts, however the same issue. But it's weird that it only affects the root alias and none of the internal pages.

Any insight would be greatly appreciated

/home/user/conf/web/example.com.nginx.ssl.conf shown below:

Code: Select all

server {
    listen      10.152.0.4:443;
    server_name example.com www.example.com;
    ssl         on;
    ssl_certificate      /home/user/conf/web/ssl.example.com.pem;
    ssl_certificate_key  /home/user/conf/web/ssl.example.com.key;
    error_log  /var/log/httpd/domains/example.com.error.log error;

    location / {
        proxy_pass      https://10.152.0.4:8443;
        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|html|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls|xlsx|ppt|pptx|odf|odp|ods|odt|pdf|psd|ai|eot$
            root           /home/user/web/example.com/public_html;
            access_log     /var/log/httpd/domains/example.com.log combined;
            access_log     /var/log/httpd/domains/example.com.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }

    location /error/ {
        alias   /home/user/web/example.com/document_errors/;
    }

    location @fallback {
        proxy_pass      https://10.152.0.4:8443;
    }

    location ~ /\.ht    {return 404;}
    location ~ /\.svn/  {return 404;}
    location ~ /\.git/  {return 404;}
    location ~ /\.hg/   {return 404;}
    location ~ /\.bzr/  {return 404;}

    include /home/user/conf/web/*nginx.example.com.conf_letsencrypt;
    include /home/user/conf/web/snginx.example.com.conf*;
}