Virtual hosts are used to run more than one web site on a single machine. Virtual hosts can be "IP-based", meaning that you have a different IP address for every web site, or "name-based", meaning that you have multiple names running on each IP address. The fact that they are running on the same physical server is not apparent to the end user. In this example I will demonstrate name-based virtual hosting.
This guide assumes you have Apache installed and working, if you need help setting up LAMP server refer back to “how to setup Debian/Ubuntu LAMP Server” article.
1.Create directory structure for each website.
# cd /var/www
# mkdir www.example.com
# mkdir www.example.com/htdocs
# mkdir www.example.com/cgi-bin
# mkdir www.example/logs
# mkdir www.example.net
# mkdir www.example.net/htdocs
# mkdir www.example.net/logs
# mkdir www.example.net/cgi-bin
# mkdir www.example.org
# mkdir www.example.org/htdocs
# mkdir www.example.org/logs
# mkdir www.example.org/cgi-bin
2.Edit apache configuration file to enable virtual hosting.
Here are the lines you should add into your Apache configuration file:
NameVirtualHost *
ServerAdmin webmaster@example.com
ServerName www.example.com
ServerAlias example.com
# Indexes + Directory Root.
DirectoryIndex index.html
DocumentRoot /var/www/www.example.com/htdocs/
# CGI Directory
ScriptAlias /cgi-bin/ /var/www/www.example.com/htdocs/
Options +ExecCGI
# Logfiles
ErrorLog /var/www/www.example.com/htdocs/logs/error.log
CustomLog /var/www/www.example.com/htdocs/logs/access.log combined
Do the same thing for each website you want to serve.
3.Restart apache.
4.use hosts file to map ip to hostname if you don’t have dns in your network.
Edit /etc/hosts in Linux or c:\windows\system32\drivers\etc\hosts in Windows
192.168.10.10 www.example.com
192.168.10.10 www.example.net
192.168.10.10 www.example.org
Dmitriy thanks for the comment, i'm also big fan of your site.
Very interesting blog. Keep working on it.
PS:
Thanks for placing my site (video4admin.com) in links. I really appreciate it :)
Post new comment