Hello,
Today we are going to talk about vHosts or Virtual Hosts within apache.
What is an Apache vHost?
Well put simply this is how apache finds a specific URL on a server with multiple web sites stored on it. A better explanation however is :
A Virtual Host utilizes a domain name to find the website associated with it on the server
What is a vHost useful for?
These are particularly useful if you run multiple websites on your server. For example
yoursite1.com is stored in /var/www/yoursite1
yoursite2.com is stored in /var/www/yoursite2
Apache will consult the vhost configuration to find what the domain is pointing to
Thats great but how do I enable them?
Well first we need to open the apache configuration file using your text editor (I will be using nano over SSH)
[root@keiran ~]# nano /etc/httpd/conf/httpd.confYou will be greeted with something similar to this
Now you must find the line
#NameVirtualHost *:80Simply remove the "#" Symbol then save and reload apache.
Now that Virtual Hosts are enabled how do I make a vHost?
Well its fairly simple. In this guide I will show you how to create a basic virual host. Scroll to the bottom of your apache configuration file and add the following tags
Now we have our VirtualHost ready to create. Lets associate it with a domain.Code:<VirtualHost *:80> </VirtualHost>
Inside your <VirtualHost> block add the following line
Congratulations your vHost now has a domain lets add the www alias to it add the next lineCode:ServerName yoursite1.com
as most people know www is a subdomain you could make it the ServerName and use the yoursite1.com as the Alias (You can make subdomains an ServerName also)Code:ServerAlias www.yoursite1.com
So far so good but how does apache know what path to point to? Good question Lets add the next line shall we
Now apache knows where your files areCode:DocumentRoot /var/www/yoursite1
Once you configure your vHost exit your editor and SAVE YOUR CONFIG!!! then restart/reload apache
OPTIONAL LINES!
ServerAdmin - This provides a way for visitors to contact you about errors in your webserver
ServerAdmin you@somedomain.com
ErrorLog - This is where the ErrorLog for the specific Domain is heldErrorLog /logs/yoursite1.com-error_logCustomLog - This is more commonly used for access LogsCustomLog /logs/yoursite1.com-access_log commonSummary
Well now we have a functioning vHost I guess this tutorial is over
Thank you for reading this guide and happy vhosting
Original : Keiran-Smith.net
Great tut for creating multi sites on one server.
How do I allocate more resources to one site then another ? For example CPU load ?
Thanks for the reply!
You cant limit CPU Usage for specific sites. However using mod_bandwidth and the quota kernel mods you can limit disk space and bandwidth for sites
lol thnaks
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks