I'm managing two domains domainA.com and domainB.com on DNS Made Easy. Both domains point to the same EC2 instance.

domainA had a HTTP redirection record for www.domainA.com to domainA.com, that record was deleted and replaced by a CNAME record for www.domainA.com to domainA.com.

domainB.com has a CNAME record for www.domainB.com to domainB.com.

When I go to http://domainB.com the page loads correctly, but when I go to http://www.domainB.com I get redirected to https://www.domainA.com, notice the secure protocol here!

My first thought was that the HTTP redirection record for domainA.com was being cached, but the guys at DNS Made Easy pointed out that executing $ curl -I http://www.domainB.com returned:

HTTP/1.1 301 Moved Permanently
Content-Type: application/x-msdownload
Connection: keep-alive
Status: 301 Moved Permanently
Location: https://domainA.com/
X-Powered-By: Phusion Passenger 4.0.53
Date: Fri, 08 Jan 2016 19:21:41 GMT
Server: nginx/1.6.2 + Phusion Passenger 4.0.53

So I looked in NGINX's sites-available directory for any HTTP redirects configured on domainA.comand domainB.com

domainA looks like this:

server {
  listen 80;
  listen 443 ssl;
  ssl_certificate    /etc/ssl/domainA.pem;
  ssl_certificate_key    /etc/ssl/domainA.key;
  ssl_protocols TLSv1.2 TLSv1.1 TLSv1;

  root /webapps/domainA/current/public;
  server_name domainA.com;
  passenger_enabled on;
  rails_env production;

And domainB looks like the following:

server {
  listen 80;

  root /webapps/domainB/current/public;
  server_name domainB.com;
  passenger_enabled on;
  rails_env production;

Nothing there, so then I thought to look in AWS but Route 53 is not even setup!

So now I'm really out of ideas, and I'm a web developer so server stuff is not really my strong suite so any ideas would be really appreciated.

  • 3
    The "Powered by phusion passenger" header suggests that this could be a misconfiguration in passenger. – DerfK Jan 8 '16 at 20:22
  • This would be easier to diagnose if you posted the actual domain names. I'm surprised it returns anything as you haven't listed the www subdomains in the nginx configuration. Add debugging to your location blocks to see what it's hitting - see how with add_header in this answer link – Tim Jan 8 '16 at 21:28
  • So I read the Passenger docs for my setup and they suggest that when you are testing with curl and you don't see the expected HTML to check the server_name directive. Changing that from domainB.com to domainB.com www.domainB.com solved the issue. Thanks @DerfK – josethernandezc Jan 8 '16 at 21:34
  • Well then I'll put it as an answer so you can mark it as correct then :-) – Tim Jan 8 '16 at 22:49

Try adding the subdomains to the server_name directive (as per comments).

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.