Apache - virtual hosts

2009-05-13 13:21:35来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折


See also
Apache topics
.
If you want to know more about virtual machines, see
http://cybernut.com/guides/virtual.html

Virtual hosts
A web server is both software and hardware.  The machine on which the web site resides is referred to as a web server.  The software which runs the web site is also referred to as a web server.  In our case, Apache (the web server) runs on our FreeBSD box (also, our web server).  But a given web server can run more than one web site.  It can achieve this multi-use by using virtual hosting.
Virtual hosting is the ability for a website to act as if it is the only web site on the machine.  Given that some web site can be idle for long periods of time, allowing many web sites to share the same hardware is a great way to reduce costs.  
A
very good explanation
appears within the Apache documentation.  For more detail, please refer to that document.
Name-based virtual hosts
For this example, we'll be making use of name-based virtual hosts.  Again, the Apache documentation
explains this term
very well.  We will also be making use of
their example
.
In this example, I've registered two names both of which translate to my FreeBSD box.   For more information on how I actually did this, see
httpd/dns
.   The two host names in question are:

  • http://freebsddiary.yi.org - no longer in use

  • http://test.freebsddiary.org

The server machine has one IP address, 192.168.0.45 which resolves to the name test.freebsddiary.org.  Here is what I've ensured is in my configuration file (/usr/local/etc/apache/httpd.conf):
NOTE: See the notes after this example.
...
Port 80
ServerName test.freebsddiary.org
NameVirtualHost 192.168.0.45
    DocumentRoot /usr/local/www/data/freebsddiary
    ServerName   
test.freebsddiary.org
    ErrorLog     /var/log/freebsddiary-error.log
    TransferLog  /var/log/freebsddiary-access.log
    DocumentRoot /usr/local/www/data/freebsddiary.yi.org
    ServerName   freebsddiary.yi.org
    ErrorLog     /var/log/freebsddiary.yi.org-error.log
    TransferLog  /var/log/freebsddiary.yi.org-access.log
DocumentRoot is the location of the html files for the given virtual website.
Newer versions of Apache can use combined logs.  Search for CustomLog in your Apache configuration file in order to see if you can use this format instaed.   In which case, these entries will be helpful as an example:

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Apache - who can publish what?

下一篇:Apache - making a group for it