Shared WebServer (Apache howto)


Using the same web server to serve more than a single website, the server has 1 IP and you have multiple URLs that you want to each map to a different document root.



Virutal Hosts, apache enables you to interpret the get request and route it to the appropriate document route based on the URL in the get request, this is done through what they call the virtual host technology, Since I’m using Ubuntu setting it up was as simple as going to /etc/apache2 and editing ports.conf. By adding the following you tell apache that whenever it gets a request with the mentioned ServerName map it to the mentioned Document route, if the URL didn’t match any of the mentioned servers route it to the first document route (/www/example1) in this example.

<VirtualHost *:80>
DocumentRoot /www/example1

# Other directives here


<VirtualHost *:80>
DocumentRoot /www/example2

# Other directives here


Once this is done a quick /etc/init.d/apache2 reload is required to refresh the settings, and then you can test it. If you receive an error message while reloading, make sure that you created the document routes mentioned in the ports.conf, and chowned them to www-data.www-data.

To test it go to /etc/hosts and add new entries that match the servers mentioned in the rules

Open your web browser and try it out (preferably by placing an obvious index file at each document route and seeing if you get it).


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s