1

I'm using CloudFlare for DNS and Digital Ocean for servers.

Let's call my website "example.com". It has been working fine.

I've now created a second server, which has a different IP. I want a new subdomain "staging.example.com" to point to this second IP.

In CloudFlare, I tried to create a second "A" record. Here is the export of my settings (partially redacted and also changed to use an example domain name):

;; A Records
example.com.    1   IN  A   192.■■■.135.106
staging.example.com.    1   IN  A   157.■■■.174.87

Browsing to example.com still works.

However, browsing to staging.example.com results in "Error 522 Connection timed out".

What am I doing wrong? How can I have a subdomain point to a different IP than its parent domain?

P.S. I thought maybe my Nginx config was the problem, but I now doubt that it's the problem because I was able to temporarily change it to say example2.com instead of staging.example.com and then temporarily change the CloudFlare DNS of this other domain that I own (example2.com), and it loaded fine.


P.P.S. 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 157.■■■.174.87.

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. Right? So what is wrong?

Ryan
  • 109
  • 11

2 Answers2

0

You can use the following script to create a subdomain on your server

#!/bin/bash
echo "Enter Subdomain You want to add (Eg:blog)"
read subdomain
echo "Enter your domain name (Eg:example.com)"
read domain
sudo chmod -R 755 /etc/apache2/
cd /etc/apache2/sites-available/
cat <<EOF >$subdomain.$domain.conf
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/$subdomain
    ServerAlias  $subdomain.$domain
    ServerName $subdomain.$domain

    <Directory /var/www/$subdomain>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order allow,deny
# remove following four lines if http authentication not required or not set up#
        AuthType Basic 
        AuthName "Restricted Content"
        AuthUserFile /etc/apache2/.htpasswd
        Require valid-user
    </Directory>

 </VirtualHost>
EOF
mkdir /var/www/html/$subdomain
echo " Add your files to /var/www/html/$subdomain "
echo "enabling subdomain................"
sudo a2ensite $subdomain.$domain
echo "Reloading apache2 ................"
sudo service apache2 reload
0

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 that I'll now go solve.

Ryan
  • 109
  • 11