How set subdomain to point to different IP address from main domain

I have 2 different servers (so 2 different IP addresses).

Currently, my domain (let’s call it example dot com) points to the first IP address.

I now want to point staging dot example dot com to the 2nd IP address.

I tried creating a second “A” record and called it “staging” and pasted in the 2nd IP address.

But browsing to staging.example.com shows “Error 522 Connection timed out”.

And if I try to ping staging.example.com, I see results from some 3rd IP address that I’m not familiar with.

So then when I try to browse to that 3rd IP address to see who it is, I get this error:

Error 1003
Direct IP access not allowed
You’ve requested an IP address that is part of the Cloudflare network. A valid Host header must be supplied to reach the desired website.

What am I doing wrong?

That’s a normal setup for many users here. If you’re proxying through Cloudflare (DNS set to :orange:), you’re going to see Cloudflare’s IP addresses for your (sub)domain when you ping it.

That 1003 error is because of the above: That’s a shared IP address at Cloudflare for many sites using Cloudflare.

I’ll post a link to some 522 tips, but if you want to test this subdomain to see if it works, go to the DNS section of the Cloudflare Dashboard and set it to :grey:.

1 Like

Thanks for your response.

I hadn’t thought of changing the orange cloud to gray (i.e. change from Proxied to “DNS only”).

After doing that and then running dig @8.8.8.8 +trace +question staging.example.com A, I do see the correct IP mentioned in the results.

So maybe that means my Nginx config is faulty, even though I have already tested that a ton and can’t see how that would be the case.

E.g. https://serverfault.com/questions/990407/how-to-host-cloudflare-dns-subdomain-at-different-ip

Now for debugging purposes my Nginx config says:

server_name staging.example.com example2.com;

And I’ve left the subdomain “A” record in CloudFlare DNS as “DNS only” (gray cloud).

Then in my CloudFlare DNS for example2.com (a different domain that I own), I temporarily pointed it to the new server’s IP.

And browsing to staging.example.com results in “This site can’t be reached staging.example.com took too long to respond. ERR_CONNECTION_TIMED_OUT” .

But browsing to example2.com works.

This leads me to believe that the Nginx config is fine.

Do you have any ideas @sdayman? I appreciate your help :slight_smile:

@sdayman Never mind.

I think the first problem was that my Page Rules were redirecting http to https, and I’d temporarily commented out the SSL parts of the Nginx config.

After uncommented the SSL parts, now browsing to https://staging.example.com/ results in:

400 Bad Request
No required SSL certificate was sent 

which is a totally separate issue. So I guess this ticket is finished.