+ Reply to Thread
Results 1 to 5 of 5

Thread: vHosting in Apache

  1. #1
    Affix is offline Learning Programmer
    Join Date
    Feb 2009
    Location
    Scotland
    Posts
    47
    Blog Entries
    2
    Rep Power
    12

    vHosting in Apache

    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.conf
    You will be greeted with something similar to this



    Now you must find the line
    #NameVirtualHost *:80
    Simply 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

    Code:
    <VirtualHost *:80>
    
    </VirtualHost>
    Now we have our VirtualHost ready to create. Lets associate it with a domain.

    Inside your <VirtualHost> block add the following line

    Code:
    ServerName     yoursite1.com
    Congratulations your vHost now has a domain lets add the www alias to it add the next line

    Code:
    ServerAlias     www.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)

    So far so good but how does apache know what path to point to? Good question Lets add the next line shall we

    Code:
    DocumentRoot     /var/www/yoursite1
    Now apache knows where your files are

    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 held
    ErrorLog /logs/yoursite1.com-error_log
    CustomLog - This is more commonly used for access Logs
    CustomLog /logs/yoursite1.com-access_log common
    Summary
    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

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Nov 2009
    Location
    London
    Posts
    866
    Blog Entries
    3
    Rep Power
    14

    Re: vHosting in Apache

    Great tut for creating multi sites on one server.

    How do I allocate more resources to one site then another ? For example CPU load ?

  4. #3
    Affix is offline Learning Programmer
    Join Date
    Feb 2009
    Location
    Scotland
    Posts
    47
    Blog Entries
    2
    Rep Power
    12

    Re: vHosting in Apache

    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

  5. #4
    arkanion is offline Newbie
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Re: vHosting in Apache

    lol thnaks

  6. #5
    genux's Avatar
    genux is offline Learning Programmer
    Join Date
    Dec 2009
    Location
    Norwich
    Posts
    79
    Rep Power
    8

    Re: vHosting in Apache

    nice post.
    Code:
    int coffeePerDay = 10; // need to cut down!!!
    Codingfriends

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Beginner Set up apache
    By jakash3 in forum Linux Tutorials, Guides and Tips
    Replies: 4
    Last Post: 06-24-2011, 07:06 PM
  2. Securing apache
    By imported_Affix in forum Linux Tutorials, Guides and Tips
    Replies: 3
    Last Post: 10-11-2009, 10:21 AM
  3. Apache & IIS
    By zeroradius in forum Computer Software/OS
    Replies: 3
    Last Post: 06-03-2009, 09:43 AM
  4. ASPX in apache
    By tekmiester in forum Linux Installation & Configuration
    Replies: 1
    Last Post: 01-28-2009, 07:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts