0

I'm running Apache2 on Ubuntu 10, and I have my site configuration files laid out numerically and in order. My default server is psychedeli.ca, but I also run another site off the same box at mahoganytales.com. Currently, both of these domains point to the same site (the one for psychedeli.ca). The declaration NameVirtualHost *:80 is in my ports.conf file, so I'm pretty sure my global server config checks out. How can I fix this?

Here are my vhost files:

001-psycho

<VirtualHost *:80>
    DocumentRoot /var/apps/psycho/public
    ServerName psychedeli.ca
</VirtualHost>

002-mahogany

<VirtualHost *:80>
    DocumentRoot /var/apps/mahogany/public
    ServerName mahoganytales.com
</VirtualHost>
tubbo
  • 598
  • 10
  • 21
  • My issue (two virtual hosts on the same IP, two domains set to direct to the same IP, all config checks out, but I still get the one site for both domains) was that **I used certbot to set up HTTPS for one site but not for the other**. That caused the server to serve only the HTTPS-enabled site. Once I configured HTTPS also for the other site, it all works fine. – edison23 Jun 04 '23 at 16:38

3 Answers3

1

try create new conf file at /etc/apache2/conf.d, e.g., vhosts.conf

with this content in it:

NameVirtualHost *
spygm
  • 11
  • 1
0

It looks like the default configuration is in effect rather than your host entries. Following is the procedure that works in Ubuntu Apache2.

First,

  • create a VirtualHost in /etc/apache2/sites-available/somesite,
  • then a2ensite somesite to make it live.
  • Finally, /etc/init.d/apache2 restart to restart apache.

If you think, you have followed the above steps, then can you please confirm, that you have your hosts files in /etc/apache2/sites-enabled/?

Rakesh Sankar
  • 9,337
  • 4
  • 41
  • 66
-2

Each domain name needs to have it's own single unique ip address, that's how different sites are found.

By using the *:80 in the virtual host directive, you're instructing Apache to listen on all IP addresses, port 80 and send it to this directory. With your second vhost, you're doing the same thing (All IP's port 80, and send it there). Well, since you're giving it two conflicting statements, it takes the first match, and uses it.

If you want to serve multiple websites, each must answer to it's own unique IP address, ie:

site aaa.com - 145.25.82.110
site bbb.com - 145.25.82.111

From there, each vhost entry will listen on it's own ip address and port for each site. In the OP's case the vhost needs to change to (using the example IPs):

&ltVirtualHost 145.25.82.110:80>
    DocumentRoot /var/apps/psycho/public
    ServerName psychedeli.ca
&lt/VirtualHost>

&ltVirtualHost 145.25.82.111:80>
    DocumentRoot /var/apps/mahogany/public
    ServerName mahoganytales.com
&lt/VirtualHost>

This instructs the server to listen on static IP 1 port 80 (as defined in the named.conf and associtated bind config files, and send it to the first site base directory, and any calls on the second static IP port 80 and send it to the second site base directory.

As for configuring bind/named, that's beyond the scope of this question...

Stephan
  • 41,764
  • 65
  • 238
  • 329
Bill
  • 1
  • You can serve multiple hostnames from a single IP address with ____ and __NameVirtualHost *__ -- you need only create separate vhost definitions with differing __ServerName__ values or use a single vhost with __ServerAlias__ listing the alternate domain names – Kasapo Dec 05 '12 at 18:30
  • Just wanted to add: DNS servers resolve IP addresses from hostnames and they can have the same IP address listed for multiple hostnames. But the rest of the explanation (that apache hits the first matching VHost and ignores the second) I believe is completely accurate. However, *something* needs to be present to disambiguate the request, and in this case, the domain name provided by the end-user/client does this and works with the servername/serveralias value(s) provided by server config. – Kasapo Dec 05 '12 at 18:43