Httpd – Apache httpd.conf: Multiple virtualhosts on a single ip

apache-2.2developmenthttpdvirtualhost

We have a local development server we have setup on a comcast business class connection with a single static ip. This is all routed through a DIR 655 router. Our issue is as follows: We have our main documentroot setup as /var/www/html of course, but the problem comes in when we try to setup our virtualhosts. We have a domain that resolves to the single static ip, and we need several sub domains. Normally you would just use a namevirtualhost pointed to the ip that you want to share, then setup the virtualhosts to meet your needs, but I don't see how this is possible with a single ip o nthe server. The ip is already sending everything to the /var/www/html documentroot directory. We're at a loss at this point. We figured an easy fix would be a second ip address, but how does one map two ip's to a single device on a low end router like the dir 655? Anyone out there have some advice?

Thanks in advance.

Best Answer

I'm not entirely sure that I understand your requirements… But, provided you don't need SSL, you can have as many virtual hosts on one IP as you'd like:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias foo.example.com foo
    DocumentRoot /var/www/example/
</VirtualHost>
<VirtualHost *:80>
    ServerName spam.com
    ServerAlias eggs.spam.com
    DocumentRoot /var/www/spam/
</VirtualHost>
Related Topic