Report this

What is the reason for this report?

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

Posted on April 30, 2021

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?



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!

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.

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!

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.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.