Prakash Raman
Prakash Raman

Reputation: 13943

Run multiple websites in Apache2 with variable subdomain

I would like to run multiple websites, and I would like each website (differentiated by a subdomain) to point to a different DocumentRoot.

My Setup

Host Machine: Mac (Lion)
Development Machine Ubuntu 10.04 (a vm using VirtualBox)

From the Mac's browser, I want to be able to access

http://website1.dev
http://website2.dev

Appreciate any help that can be given.

Note: When I try to use a ServerName I get

 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

Upvotes: 0

Views: 913

Answers (1)

Reggie
Reggie

Reputation: 654

Have you seen or read the VirtualHost examples provided in the latest online Apache documentation? This specific section (the first one on the list) on "running several name-based web sites on a single IP address" should help you, it seems to be exactly what you are attempting to do. Here's the snippet, modified for your needs:

# Ensure that Apache listens on port 80
Listen 80

<VirtualHost *:80>
    DocumentRoot /www/website1
    ServerName website1.dev
    # (Other directives here)
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /www/website2
    ServerName website2.dev
    # (Other directives here)
</VirtualHost>

You will have to elaborate more if this does not work. What's your Apache version? What are you current httpd.conf and virtualhost.conf file contents?

Upvotes: 1

Related Questions