Question

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

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?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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,

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!