Score:-1

Cloudflare DNS keeps redirecting to a wrong site on the same server

dk flag

I have a strange DNS setting glitch here.

We are rebuilding and migrating two old sites to a new VPS server. They coexist now as below. We use Cloudflare DNS (NO reverse proxy).

Site A: aaa.example.com (on an old server)

Site B: bbb.example.com (same as Site A)

New Site A: aaa2.example.com (on the new VPS built by Ubuntu 21.10 + Nginx + WordPress)

New Site B: bbb2.example.com (same as New Site A)

Now both new sites are finished and we need to officially launch them. Here are what we did in Cloudflare DNS:

  1. We first added an A record with name = aaa2 and IP = VPS IP. This works fine and we could access the new site with the URL aaa2.example.com (this is how we developed the new site).

  2. And now we added a CNAME record with name = aaa and target = aaa2.example.com, and then in WordPress Dashboard we changed both WordPress Address and Site Address in Settings > General to https://aaa.example.com. We also used a plugin called Better Search Replace to replace all strings aaa2.example.com in the database to aaa.example.com.

I think it’s a proper setup because this works perfectly and now the site A is fully transferred to the new site A on the VPS. We can use the official URL aaa.example.com to access it.

  1. As we did in 1., we added an A record bbb2 for the new site B and it just works fine.

  2. Here comes the problem. As we did in 2., we added a CNAME record with name = bbb and target = bbb2.example.com, but somehow now the URL bbb.example.com gets redirected to aaa.example.com (new site A)! I cannot understand why this happens.

bbb2.example.com still works (leading to new site B).

If in WordPress Dashboard we changed both WordPress Address and Site Address in Settings > General to https://bbb.example.com or just used the plugin to replaced all strings, both bbb.example.com and bbb2.example.com would get redirected to aaa.example.com. It’s the worst result because we would lose all access to the new site B and had to use the snapshot backup on the VPS to restore the whole system.

Any thoughts about how to solve this redirect error in Cloudflare DNS?

I got stuck here for over 1 month. I'm pretty sure there is no typo in the DNS records. ChatGPT told me to check these things:

  1. Deactivate plugins that may cause this redirect: I couldn't find any plugin that could lead to this. Also these two new sites use exactly the same plugin combination.

  2. Check the SSL certificate: the server administrator used a wildcard Certbot setting so all subdomains should be covered.

  3. Check the Nginx settings: Unfortunately I'm not the administrator so can't access the server. I have no knowledge on Nginx anyway.

Score:1
cd flag

I'm pretty sure the problem is in NGInx... Ask the SysAdmin (who has access to NGInx) to create or duplicate the configuration file for site A, creating the file for site B, because that way NGInx will find the settings. Or else he can simply create a redirect: if ( $request_filename ~ content/unique-page-name/ ) { rewrite ^ http://sitedomain.co.uk/new-name/unique-page-name/? permanent; }

Keith Langmead avatar
us flag
I agree, if requests for `bbb.example.com` are being directed to the new VPS then Cloudflare's side of things is working. DNS records will get you to the right server, but the VPS/Nginx will control which site is displayed when it receives the request, so one for the Sysadmin to look at and determine why Nginx is getting the request and returning the wrong site.
Acon avatar
dk flag
Thank you guys. Contacting the SysAdmin now and hopefully he can get it fixed soon.
Acon avatar
dk flag
Problem solved. SysAdmin just replied and said that bbb.example.com needs to be added to /etc/nginx/sites-enabled/bbb2.example.com/ as **server_name bbb2.example.com bbb.example.com;**. He got it done and now the New Site B works as it should be!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.