Question

Can I add a virtual host for subdomain that is hosted by another server?

Posted April 30, 2021 247 views
Ubuntu 20.04

I followed How To Set Up Apache Virtual Hosts on Ubuntu 18.04 and it is working for two domains, example1.com and example2.com.

Both of them are hosted in a DigitalOcean droplet.

I have another website on Bluehost and I’d like to host its subdomain on the DO droplet.
I created a DNS record newsletter.example3.com and www.newsletter.example3.com with my DigitalOcean IP address.

I created newsletter.example3.com.conf:

<VirtualHost *:80>
        ServerAdmin my.name@gmail.com
        ServerName newsletter.example3.com
        ServerAlias www.newsletter.example3.com
        DocumentRoot /var/www/newsletter.example3.com/public_html

        <Directory /var/www/newsletter.example3.com/public_html>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <IfModule mod_dir.c>
            DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
        </IfModule>
        RewriteEngine on
        RewriteCond %{SERVER_NAME} =www.newsletter.example3.com [OR]
        RewriteCond %{SERVER_NAME} =newsletter.example3.com
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

I run sudo a2ensite newsletter.cecilieo.com and restarted apache.

sudo systemctl restart apache2

Problem 1: When I go to newsletter.example3.com, it shows example1.com.
Problem 2: When I run certbot, it returns errors:

sudo certbot --apache -d newsletter.cecilieo.com -d www.newsletter.example3.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for newsletter.example3.com
http-01 challenge for www.newsletter.example3.com
Waiting for verification...
Challenge failed for domain newsletter.example3.com
Challenge failed for domain www.newsletter.example3.com
http-01 challenge for newsletter.example3.com
http-01 challenge for www.newsletter.example3.com
Cleaning up challenges
Some challenges have failed.

IMPORTANT NOTES:
 - The following errors were reported by the server:

   Domain: newsletter.example3.com
   Type:   unauthorized
   Detail: Invalid response from
   https://newsletter.example3.com/.well-known/acme-challenge/uMURe80sprzaxrEGzyu7F1CycxEhc-Bd-DVFAM_f09g
   [2606:4700:3030::6815:2eca]: "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD
   HTML 2.0//EN\">\n<html><head>\n<title>404 Not
   Found</title>\n</head><body>\n<h1>Not Found</h1>\n<p"

   To fix these errors, please make sure that your domain name was
   entered correctly and the DNS A/AAAA record(s) for that domain
   contain(s) the right IP address.
 - The following errors were reported by the server:

   Domain: www.newsletter.example3.com
   Type:   tls
   Detail: Fetching
   https://www.newsletter.example3.com/.well-known/acme-challenge/PbVou0UruJkHOZqWPhAOiUWTOkTw6_aMPi-6ScVxyNQ:
   remote error: tls: handshake failure

   To fix these errors, please make sure that your domain name was
   entered correctly and the DNS A/AAAA record(s) for that domain
   contain(s) the right IP address. Additionally, please check that
   you have an up-to-date TLS configuration that allows the server to
   communicate with the Certbot client.

Can I add a subdomain hosted by another server?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
2 answers

Hi @okadashinichi2819,

Yes, you can add the subdomain as long as it’s pointed to your Droplet.

I think your issue is coming from the DNS propagation. Remember that DNS changes can take up to 24 hours to fully propagate.

Everything else seems to be alright, the configuration file looks good!

  • Hi @okadashinichi2819,

    I just opened your website and saw that it’s loading properly for me!

    Did you make any changes or it was the DNS that propagated?

    • Hi, Thank you for your reply.
      Example1.com is codewithshin.com and newsletter.example3.com is newsletter.cecilieo.com.

      After 20 hours, newsletter.cecilieo.com is redirected to codewithshin.com’s Under Construction page.

      It is redirecting to the DigitalOcean IP address, so DNS is ok. But my server is not showing means my setup is something wrong.

      What could be the reason that one virtual host is showing another virtual host?

      • I see you were able to resolve the issue in the later replies but I just wanted to mention that in such cases,

        I would look into removing my browser cache as well. I’ve had cases where the cache was causing all kinds of issues for me.

  • I just checked ping and it’s still pointing to another IP address. So I will wait. Thanks for your help.

  • I use Cloudflare and I changed the proxy traffic for the subdomain NOT through Cloudflare.
    And it is pointing to my DigitalOcean IP address. But it still shows another website “Under Construction”, instead of “Success! The newsletter.cecilio.com virtual host is working!”

    I am not sure what I’m doing wrong.

Ok, I solved it. I run $ sudo certbot --apache -d .... for with/without www.
Then it is working.
Oh, dear.
Thank you for the help.

  • Hi @okadashinichi2819,

    I’m glad to hear you were able to resolve the issue! Sorry I was not here sooner I was on holiday and was not around a laptop.

    Anyway, thank you for sharing your resolution as well!