I am going to cover the basics of Name Based Virtual Hosting using Apache2 running on a Debian GNU/Linux Server.
The advantage of Name Based Virtual hosting is that you can host multiple websites from an Apache2 Web server and all these websites only require one static I.P Address and also the requirement that your domain name should resolve to the I.P Address of your server.
Steps
——-
Step 1:First let us create the document root directories for the virtual domains example.com,example.org and example.net
————————————————–
root@zion:~# mkdir /home/www
root@zion:~# mkdir /home/www/www.example.com
root@zion:~# mkdir /home/www/www.example.com/htdocs
root@zion:~# mkdir /home/www/www.example.com/cgi-bin
root@zion:~# mkdir /home/www/www.example.com/logs
root@zion:~# mkdir /home/www/www.example.net
root@zion:~# mkdir /home/www/www.example.net/htdocs
root@zion:~# mkdir /home/www/www.example.net/logs
root@zion:~# mkdir /home/www/www.example.net/cgi-bin
root@zion:~# mkdir /home/www/www.example.org
root@zion:~# mkdir /home/www/www.example.org/htdocs
root@zion:~# mkdir /home/www/www.example.org/logs
root@zion:~# mkdir /home/www/www.example.org/cgi-bin
——————————————————-
Please note that I have created separate directories for
htdocs,logs,cgi-bin
Step 2: To enable virtual hosts in your Apache 2 Configuration.
For this let us create a file called /etc/apache2/conf.d/virtual.conf and the following content in it.
——————————————
#
# We’re running multiple virtual hosts.
#
NameVirtualHost *
——————————————
3) Create host files in /etc/init.d/sites-available in the following format for example.com
——————————————————–
ServerAdmin webmaster@example.com
ServerName www.example.com
ServerAlias example.com
# Indexes + Directory Root.
DirectoryIndex index.html
DocumentRoot /home/www/www.example.com/htdocs/
# CGI Directory
ScriptAlias /cgi-bin/ /home/www/www.example.com/cgi-bin/
Options +ExecCGI
# Logfiles
ErrorLog /home/www/www.example.com/logs/error.log
CustomLog /home/www/www.example.com/logs/access.log combined
——————————————————–
Create similar virtual host files for example.net and example.org
4) Now enable the sites by running the command a2ensite
———————————————————
root@zion:~# a2ensite www.example.com
Site www.example.com installed; run /etc/init.d/apache2 reload to enable.
root@zion:~# a2ensite www.example.net
Site www.example.net installed; run /etc/init.d/apache2 reload to enable.
root@zion:~# a2ensite www.example.org
Site www.example.org installed; run /etc/init.d/apache2 reload to enable.
———————————————————–
This will create a symbolic link between the files for the domains from /etc/init.d/sites-available to /etc/init.d/sites-enabled.
5) Restart apache2 with the command /etc/init.d/apache2 restart.
I had the following situation and did not know how to resolve:
1. I created multiple websites and configured Apache on Debian on my home computer.
2. I configured a HOT SPOT router to give access to the web on port 80 and to putty on port 22.
3. For one of the websites I bought a DNS domain name so it can be accessed by everybody.
But when I had the multiple sites configured, my main website would be replaced with either the second or the third website that I had configured. That’s why I had to set the main one to default and to remove the others.
Now I would like to do some work and would like to be able to access each of them without affecting my main one. How do I accomplish that ? (I don’t mind to give to users from outside my network the IP address instead of some-website.com