How to set up virtual hosts on Apache 2.2

15,437

Solution 1

Just have 2 virtual hosts defined like this, but with differeing DocumentRoots:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/docs/dummy-host.somecompany.com"
    ServerName dummy-host.somecompany.com
    ServerAlias www.dummy-host.somecompany.com
    ErrorLog "logs/dummy-host.somecompany.com-error.log"
    CustomLog "logs/dummy-host.somecompany.com-access.log" common
</VirtualHost>

<VirtualHost *:8089>
    ServerAdmin [email protected]
    DocumentRoot "/docs/dummy-host.somecompany.com"
    ServerName dummy-host.somecompany.com
    ServerAlias www.dummy-host.somecompany.com
    ErrorLog "logs/dummy-host.somecompany.com-error.log"
    CustomLog "logs/dummy-host.somecompany.com-access.log" common
</VirtualHost>

Solution 2

First you need to instruct Apache to listen on the ports you need:

Listen 80
Listen 8089

Second you need to tell it what to do with 80 and 8089 traffic:

<VirtualHost *:80>
    DocumentRoot /website/site80
    ServerName internet.dev
</VirtualHost>

<VirtualHost *:8089>
    DocumentRoot /website/site8089
</VirtualHost>

Third you need to "allow" Apache to use those directories:

<Directory "C:/website/site80">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

<Directory "C:/website/site8089">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
Share:
15,437
Cuga
Author by

Cuga

Programming is easy. The challenge is in understanding the problem.

Updated on August 22, 2022

Comments

  • Cuga
    Cuga over 1 year

    Can anyone direct me to a good tutorial on how to set up virtual hosts using Apache 2.2? Here's my situation:

    I have Apache running on my laptop and I want two websites-- one on port 80 and one on port 8089. I want to access each site from the other computer on my network by entering the computer's IP address, such as http://192.168.1.102 and http://192.168.1.102:8089. Yet when I enter the second url, it directs me to the website running on port 80.

    Thanks in advance for any help.

  • Cuga
    Cuga almost 15 years
    Since I don't have any host names, what could I use for the following attributes-- My IP address? ServerName dummy-host.somecompany.com ServerAlias www.dummy-host.somecompany.com
  • PaulJWilliams
    PaulJWilliams almost 15 years
    The only thing that really matters is DocumentRoot. Im pretty sure (though not certain), that you could omit all other declarations and just point your browser to localhost:80 or localhost:8089 and you'll get the corresponding files being serveed from the appropriate DocumentRoot
  • Cuga
    Cuga almost 15 years
    I just tried what you said-- no difference. Whether I type in localhost:80 or localhost:8089, I still see the same webpage I have at port 80 and not the one I have at port 8089.
  • Cuga
    Cuga almost 15 years
    It's still redirecting me to the site at port 80. I really don't get it.