Friday 7 June 2013

Multiple hosted websites are redirecting to only one of my sites on Apache

I had an interesting problem today.

I am attempting to host 3 different web sites on an apache configuration on a raspberry pi. Individually, I can launch each webpage without issue and have the site show up. However, somehow, when I enabled more than one site at a time, each one on different ports, it would show only one site across all ports.

I tried configuring different sites with different ports, changed <Directory> tags to see if my directories were overriding each other, etc.

Most of the data is stored in /var/www/[site-name], so it was only until I tried adding another site at /var/www/[different-site-name] and have it still happen that I knew it was not a path conflict. I fudged with the apache settings for a while to no effect.

A little voice in my head hinted at one of the configuration files I had used a long time ago, the /etc/apache2/conf.d/virtual.conf file. I checked it out, and it had this to say:


NameVirtualServer *


Now, in my website ports.conf file, I specified lines like this:
NameVirtualServer *:80
NameVirtualServer *:8081
NameVirtualServer *:8082

Somehow it clicked. I disabled the /etc/apache2/conf.d/virtual.conf contents by changing the line to this:

# NameVirtualServer *

saved and restarted apache.

Now everything works as configured.

It may seem like a trivial problem, but it cost me a couple hours of my valuable time and I *could not* find a solution on google. Granted, I didn't scour the bowels of the internet for this small problem.

Hopefully this will help others in my position.

(Performed on a Raspbian installation)