1

I am quite a noob on Ubuntu but I had to install it on a VPS to display two different websites as sub-domains. One of them is a Drupal 8 website, the other one is a Static html website (index.html)

I got both websites on /var/www and I think I configured everything correctly on apache2 because I added the two subdomains to hosts file to access locally and do some tests and they work fine.

When I type old.myaddress.com or new.myaddress.com both of them load locally. However, if I try to access through internet or from another computer, it will only load the Drupal one, always. Why?

Worth to mention that I got a Domain and configured both old.myaddress.com and new.myaddress.com subdomains to redirect to the same IP (my VPS server IP). As far as I understand, apache should send the user to the different sites?

These are my .conf files inside etc/apache2/sites-available:

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName www.myaddress.com
    ServerAlias old.myaddress.com
    DocumentRoot /var/www/oldwebsite/myaddress.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName www.myaddress.com
    ServerAlias new.myaddress.com
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

To clarify, I'm asking where the missing configuration is. If loading the websites locally works, it may still be apache? It's my DNS? my ISP? Drupal configuration? I'm quite lost.

5
  • I was hoping one of the wise ones would answer. But as it doesn't seem to happen, my take on this is that: hosts file only works locally, not in a network, so its configuration won't work externally. As old.myaddress.com and new.myaddress.com point to the same IP, apache serves the first site in available sites. You shoul configure your sites with different IPs, and have a DNS server that point your domains to those IPs. Easier said than done. Take this with a grain of salt. Hope it helps. Aug 23, 2019 at 22:50
  • Different ips wouldn't work for me. I'd need both websites on same IP (as subdomains).
    – Saelyth
    Aug 26, 2019 at 16:31
  • As @guillermochamorro pointed out, the hosts-file will only work locally on your VPS. In order to make these 2 addresses (with subdomains) available on the internet, you have to own / rent the domain ("myaddress.com" in your case) and bind your static-ip + port to the address (e.g. hostpapa.ca/knowledgebase/add-subdomain-points-ip-address ). I am not sure whether you need an "A record" or "CNAME" entry, but it probably would be one of those. IF you want them available on your intranet, it would be slightly different. Edit: try your domain configuration and bind ip + port.
    – Igor
    Aug 26, 2019 at 16:52
  • myadress.com was merely a placeholder name. I own my domain but I'd rather not make that name public here on SO (security of the server is not yet perfect). The domain and the subdomains are bound to my ip + port. The issue still persists. Note: I don't use My CPanel. I am using Ubuntu Desktop.
    – Saelyth
    Aug 27, 2019 at 8:07
  • 2
    Change ServerName in each to old.myaddress.com and new.myaddress.com. You can remove then ServerAlias entries. Aug 27, 2019 at 17:12

2 Answers 2

0

I'm assuming your DNS domain is correctly configured and new.myaddress.com and old.myaddress.com correctly resolve to your server IP. You can check that on another machine with:

nslookup old.myaddress.com

It's odd that your configuration works locally and not remotely, if these names resolves to the same IP. Is a ping to each address ends up to the same IP address than nslookup reports?

Another thing, the ServerName should't have the same value for multiple VirtualHost. You can use any ServerAlias you want as long as the same value is used only once. I'd remove the www.myaddress.com from the old website VirtualHost configuration.

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName old.myaddress.com
    DocumentRoot /var/www/oldwebsite/myaddress.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName www.myaddress.com
    ServerAlias new.myaddress.com
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
0

Apparently I had to set the correct IPv4 and IPv6 to the record A and record AAAA of the DNSs of my sub-domains.

For DNS providers like 1and1 (Ionos), when you set up a domain or a sub-domain it assumes it's hosted at their locations, and in order to bind it to an external hosting you need to manually edit the records A and AAAA to point to your ip server.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .