Redirecting to wrong canonical address

I’ve just updated to the latest trellis using a new DO droplet.
Everything is working perfectly except for my www redirect specified in my wordpress_sites.yml

wordpress_sites.yml:

domain1.com:
site_hosts:
  - canonical: domain1.com
    redirects:
      - www.domain1.com
  - canonical: sub.domain2.com

www.domain1.com is redirecting to sub.domain2.com instead of domain1.com

My domain1.com.conf has this:

server {
  listen 80;

  server_name  domain1.com sub.domain2.com ;
}

⋮

server {
  listen 80;
  server_name www.domain1.com;

  include acme-challenge-location.conf;

    location / {
      return 301 $scheme://domain1.com$request_uri;
    }
  }

Any thoughts would be appreciated.

The domain1.com.conf looks correct. I presume it looks correct to you too, so I guess we’re both surprised by the redirect from www.domain1.com to sub.domain2.com. The second server block should match the the www.domain1.com request and return 301 to domain1.com.

Were there any failures during initial provisioning?

Could you SSH in to the server and…

  • check the nginx config by running sudo nginx -t
  • reload nginx by running sudo service nginx reload
  • then test the redirect again, maybe even in a different browser (Chrome caches redirects)

I’m not familiar enough with the possibilities to catalogue them, but are there any other services involved that could be responsible for the redirect (DNS settings, caching proxies, etc.)?

Edit: Maybe turn rewrite_log on and check your logs

Thanks @fullyint - was just a caching issue. Will think to check other browsers in the future.

1 Like