2

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 webmaster@localhost.com
    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 webmaster@localhost.com
    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.

  • 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. – guillermo chamorro Aug 23 at 22:50
  • Different ips wouldn't work for me. I'd need both websites on same IP (as subdomains). – Saelyth Aug 26 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 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 at 8:07
  • 2
    Change ServerName in each to old.myaddress.com and new.myaddress.com. You can remove then ServerAlias entries. – Michal Przybylowicz Aug 27 at 17:12
0

There could potentially be so many issues so here are a few things you can try:

  1. The hosts file locally just tells your PC which IPs to listen to, which should generally be just 127.0.0.1. When you create custom domains locally you'd add them to hosts, but using an ISP they will manage their own hosts file. If you have a completely dedicated VPS then just do exactly what you did locally.

  2. For domains to be publicly available on the internet it doesn't matter what you do in Apache, those domains have to be registered with a domain registrar to be able to route and find them. So even if you did everything correctly, if you haven't added those subdomains to your DNS registration then they won't be accessible on the internet. So if you own example.com and you registered that with an ISP, then also make sure to register subdomain.example.com and subdomain2.example.com with that ISP.

  3. Make sure that your Apache config itself is configured the same, the hosts might be perfectly the same, but you may have forgotten to allow rewrite or some other permission in which case it might just be completely ignoring your .conf file settings. If the Apache configuration is managed by your ISP then make sure that they even allow you to do custom hosts, which most ISPs don't, otherwise you'd have to use .htaccess files to rewrite to different sites internally or you'd have to manage that from your DNS console.

  4. Make sure you didn't forget something silly like creating symlinks to the sites-enabled directory, so those sites are actually available, or restarting your Apache server.

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 webmaster@localhost.com
    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 webmaster@localhost.com
    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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.