Some notes I took to get virtual hosting to work with Apache 2.x on Ubuntu 10.04. I will probably go back and clean it up later. Not saying this is the right way to do it, but it is what was done. I may also have missed a step or two. Oh well for the middle of the night, who knows what I did. In any case this is for private networks only. WARNING: IT IS NOT SECURE (i.e Do not use on a live server to the internet and if you do, do it at your own risk).

Note: This project assumes you already have all the Apache modules you need. If you run into a problem please get expert help if you are unsure as to what to do.

Mod hosts files for host and dns, but use actual server ip. You will need to talk to the dns admin about modifying the dns server.

127.0.0.1       localhost oesrvr1
127.0.1.1       oesrvr1 www.softserv.com

192.168.1.31    oesrvr1 www.softserv.com 
192.168.1.32    oesrvr3
192.168.1.99    printer1
192.168.1.98    printer2
192.168.1.30    nas

# The following lines are desirable for IPv6 capable hosts
...

Create a virtual.conf in /etc/apache2/conf.d

#
# enable multiple virtual hosts
#
NameVirtualHost *

Mod /etc/apache2/sites-enabled/000-default

NameVirtualHost *
<VirtualHost *>
	ServerAdmin webmaster@localhost
	
	DocumentRoot /var/www/
	<Directory />
		Options FollowSymLinks
		AllowOverride None
	</Directory>
	<Directory /var/www/>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride None
		Order allow,deny
		allow from all
		# This directive allows us to have apache2's default start page
                # in /apache2-default/, but still have / go to the right place
                #RedirectMatch ^/$ /apache2-default/
	</Directory>


	ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
	<Directory "/usr/lib/cgi-bin">
		AllowOverride None
		Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
		Order allow,deny
		Allow from all
	</Directory>

	ErrorLog /var/log/apache2/error.log

	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel warn

	CustomLog /var/log/apache2/access.log combined
	ServerSignature On

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

<VirtualHost *>
ServerName oesrvr1
ServerAlias oesrvr1
ServerAdmin eddie@oesrvr1
DocumentRoot /var/www
<Directory /var/www >
Options FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>

<VirtualHost *>
ServerName www.softserv.com
ServerAlias www.softserv.com
ServerAdmin eddie@oesrvr1
DocumentRoot /var/www/www.softserv.com/html
<Directory /var/www/www.softserv.com/html >
Options FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>

Repeat for each virtual host
[
Make web server directory. (/var/www already created)

$ mkdir -p /var/www/www.softserv.com/html

or

$ sudo mkdir /var/www/www.softserv.com
$ sudo mkdir /var/www/www.softserv.com/html

Create server detail file for each file in /etc/apache2/sites-available/

oesrvr1

<VirtualHost *>
ServerName oesrvr1
ServerAlias oesrvr1
ServerAdmin eddie@oesrvr1
DocumentRoot /var/www
<Directory /var/www >
Options FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>

http://www.softserv.com

<VirtualHost *>
ServerName www.softserv.com
ServerAlias www.softserv.com
ServerAdmin eddie@oesrvr1
DocumentRoot /var/www/www.softserv.com/html
<Directory /var/www/www.softserv.com/html >
Options FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>

Set a link for each file in /etc/apache2/sites-enabled

$ cd /etc/apache2/sites-enabled
$ sudo ln -s ../sites-available/oesrvr1
$ sudo ln -s ../sites-available/www.softserv.com

Enable sites;

$ sudo a2ensite oesrvr1
$ sudo a2ensite http://www.softserv.com
]

Now that we have the server files done, we need a page to start out with to serve. w3schools,com is a good place to learn how to set up web pages or you can get your own webmaster.

Create index.html in each hosts DocumentRoot. My oesrvr1 web pages were already set up.

$ sudo nano /var/www/www.softserv.com/html/index.html

index.html

<html>
<body>

Hello world!

</body>
</html>

Reload and restart server to use the updated configuration files.

$ sudo /etc/init.d/apache2 reload
$ sudo /etc/init.d/apache2 restart

Time to test the sites.

$ firefox oesrvr1 &
$ firefox http://www.softserv.com &

Good day!

Advertisements