⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asg04.htm

📁 apache技术手册
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<HTML>

<HEAD>

<TITLE>Apache Server Survival Guide asg04.htm </TITLE>

<LINK REL="ToC" HREF="index.htm" tppabs="http://docs.rinet.ru:8080/Apachu/index.htm">

<LINK REL="Index" HREF="htindex.htm" tppabs="http://docs.rinet.ru:8080/Apachu/htindex.htm">

<LINK REL="Next" HREF="asg05.htm" tppabs="http://docs.rinet.ru:8080/Apachu/asg05.htm">

<LINK REL="Previous" HREF="asgpt2.htm" tppabs="http://docs.rinet.ru:8080/Apachu/asgpt2.htm"></HEAD>

<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<!--#exec cmd="/www/docs/ssi-bin/restricted_search.ssi"-->





<!--#exec cmd="/www/docs/ssi-bin/inc.ssi"-->






<A NAME="I0"></A>

<H2>Apache Server Survival Guide asg04.htm</H2>

<P ALIGN=LEFT>

<A HREF="asgpt2.htm" tppabs="http://docs.rinet.ru:8080/Apachu/asgpt2.htm" TARGET="_self"><IMG SRC="purprev.gif" tppabs="http://docs.rinet.ru:8080/Apachu/purprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>

<A HREF="index.htm" tppabs="http://docs.rinet.ru:8080/Apachu/index.htm" TARGET="_self"><IMG SRC="purtoc.gif" tppabs="http://docs.rinet.ru:8080/Apachu/purtoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>

<A HREF="asg05.htm" tppabs="http://docs.rinet.ru:8080/Apachu/asg05.htm" TARGET="_self"><IMG SRC="purnext.gif" tppabs="http://docs.rinet.ru:8080/Apachu/purnext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>


<HR ALIGN=CENTER>

<P>

<UL>

<UL>

<UL>

<LI>

<A HREF="#E68E29" >Building a Virtual Site</A>

<LI>

<A HREF="#E68E30" >Configuring a Virtual Host</A>

<LI>

<A HREF="#E68E31" >The &lt;VirtualHost&gt; Directive Section</A>

<UL>

<LI>

<A HREF="#E69E24" >BindAddress</A>

<LI>

<A HREF="#E69E25" >Listen</A></UL>

<LI>

<A HREF="#E68E32" >Multihoming: IP-Intensive Virtual Hosts</A>

<UL>

<LI>

<A HREF="#E69E26" >ifconfig alias</A>

<UL>

<LI>

<A HREF="#E70E1" >Solaris Virtual Interfaces</A></UL>

<LI>

<A HREF="#E69E27" >The VIF Patch</A>

<LI>

<A HREF="#E69E28" >PPP</A>

<UL>

<LI>

<A HREF="#E70E2" >Configuring the PPP Interfaces</A></UL></UL>

<LI>

<A HREF="#E68E33" >Apache Non-IP Virtual Hosts</A>

<UL>

<LI>

<A HREF="#E69E29" >A Workaround for Clients That Don't Support Non-IP Virtual Hosts</A></UL>

<LI>

<A HREF="#E68E34" >Summary</A></UL></UL></UL>

<HR ALIGN=CENTER>

<A NAME="E66E4"></A>

<H1 ALIGN=CENTER>

<CENTER>

<FONT SIZE=6 COLOR="#FF0000"><B>4</B></FONT></CENTER></H1>

<BR>

<A NAME="E67E7"></A>

<H2 ALIGN=CENTER>

<CENTER>

<FONT SIZE=6 COLOR="#FF0000"><B>Virtual Hosts</B></FONT></CENTER></H2>

<BR>

<P>This chapter covers a powerful feature of the Apache server: virtual hosts. Virtual hosting allows a single instance of the Apache Web server to run several Web sites, each accessible by its own domain name. Apache was one of the first HTTP servers to provide support for building virtual sites. While servers from NCSA and others also provide virtual-site support, Apache provides better performance and has more features than the others.

<BR>

<P>At first glance, the main advantage of a virtual site seems mostly cosmetic: It allows many Web sites to be addressed by their own domain name on a single shared machine. However, this cosmetic advantage has several positive effects on the administration of your site and how others use it. Virtual hosts are frequently created with the intent to do the following:

<BR>

<UL>

<LI>Make it easier for customers to access Web sites on leased servers. Since the lessee can use his own domain name, addresses tend to be shorter. This helps to project a professional identity to the world. Users are more likely to remember the shorter address since the domain name (hopefully) has some relevance to the corporate name.

<BR>

<BR>

<LI>Reduce and maximize the computer and networking hardware. Several low-traffic sites can be housed in a single machine, thus reducing the costs of hosting the site.

<BR>

<BR>

<LI>Reduce the human costs associated with system administration. Instead of managing and configuring a dedicated server for each domain, the webmaster only needs to maintain a few configuration files and a minimal number of boxes. This translates into a reduced number of systems that need to be upgraded or maintained, thus simplifying network maintenance.

<BR>

<BR>

</UL>

<P>Because most Web sites don't generate enough traffic to exhaust the resources of a single machine, it is desirable from an administrative point of view to allow a single server to masquerade and behave as several different machines. Instead of dedicating hardware and monetary resources to each site hosted, a few server configuration commands produce the same result: a virtual site. Because the expense required to set up a Web server can be shared between several sites, the time required to configure and manage Web sites is reduced dramatically.

<BR>

<P>Virtual hosts have the positive side effect of making Web pages portable. When a site is virtual, it&#146;s easy to move it to a different Web server in the same network or somewhere else. It becomes a matter of transferring the site's HTML pages to a new machine and modifying the site's Domain Name System (DNS) information to point to the new server. To accommodate DNS update lapses, simply create a redirection on the old server. This allows traffic to continue flowing without a lapse, which is an important issue with sites that thrive on traffic as a way of generating business.

<BR>

<P>Historically, when you wanted a site hosted using your domain, your only viable option was to purchase (or lease) a computer and have it configured as a Web server. Incurred with these costs was the expense of managing the server. These costs, easily thousands of dollars, motivated Internet Service Provider (ISPs) to consider additional ways of supporting multiple Web sites in one host, which resulted in a few early solutions, such as the &quot;home page&quot; approach.

<BR>

<P>The home page approach was one early way to support multiple sites on a single Web server. This approach differentiates each site by adding extra address information, such as a user's home paqe.

<BR>

<P>The home page approach creates addresses that look like this:

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">http://www.isp.dom/~<I>name</I></FONT></PRE>

<P>or, worse yet, uniform resource locators (URLs) that list some path to a directory on the server tree:

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">http://www.isp.dom/<I>name</I></FONT></PRE>

<P>The home page approach is an appropriate way to serve local users' pages. But when it comes to serving corporate information that is going to be accessed more frequently and by a large number of viewers, this solution creates ugly addresses that are hard to remember, long to type, prone to user error, and not very professional looking.

<BR>

<BR>

<A NAME="E68E29"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Building a Virtual Site</B></FONT></CENTER></H3>

<BR>

<P>The terms <I>virtual host</I>, <I>virtual site</I>, and <I>multihomed server</I> are generally used interchangeably to describe a server that supports multiple domain names. To make matters easier to understand, I find it best to limit the scope of these terms to their appropriate meanings: To create a virtual site, you need to configure a virtual host; for the virtual host to work, you may have to create a multihomed server; and obviously, there's a difference in tone. How you build a multihomed server depends on which version of Apache you are using and some other technical issues. &quot;So what's the difference?&quot; you ask. Semantics; but clarity here will help in describing the process.

<BR>

<P>A multihomed computer is one that can answer to multiple IP addresses. A computer that is accessible by multiple names (such as mailhost.foo.com and www.foo.com) that resolve to the same IP address is not a multihomed computer.

<BR>

<P>Aliasing a capability provided by DNS in a CNAME (canonical name) resource record or by listing multiple machine names on the /etc/hosts file after an IP address, is just a convenience for people accessing a networked resource. In general, people have a hard time remembering names, and some names such as www or ftp are typically standardized for machines that host services with the same name. Users only need to remember the domain name when those resources use traditional names, such as www.apple.com, mailhost.apple.com, or ftp.apple.com. A multihomed computer needs more than that. It must answer to two or more different IP addresses such as 1.2.3.4. IP addresses are assigned by your Internet network provider when you sign up with them.

<BR>

<P>A <I>virtual site</I> is a Web site that resides on a server with other Web sites. Each Web site is accessible by its own name and shares all the hardware resources with other virtual sites. Although all requests are answered by the same HTTP server process, different home pages are returned for each site depending on the name or IP address used to access the information.

<BR>

<P>Another networking issue that you will have to address before you can multihome is the DNS; DNS provides the machine name to the IP translation service. While computers like to address each other using numbers, people prefer using names. DNS translates names into numbers and numbers into names. Chances are that if you have a connection to the Internet, you are running a name server. If you are not, someone else is running it for you. If you are not running your own DNS, you'll need to coordinate with your network administrator to implement any addition or change to the DNS.

<BR>

<BR>

<A NAME="E68E30"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Configuring a Virtual Host</B></FONT></CENTER></H3>

<BR>

<P>A virtual site is configured by the &lt;VirtualHost&gt; directive, which allows you to override several configuration directives based on the site's name or IP address. This allows you to specify a different DocumentRoot directory for each virtual site, so a single instance of the HTTP server can return different Web sites for each of the virtual sites it hosts.

<BR>

<P>Right from the beginning, the Apache server provided the necessary infrastructure to allow server-side support for virtual hosts. The only requirement was that the server needed to answer to different IP addresses. This technique, which still works reliably, requires the creation of a multihomed server. Multihomed servers have a few downsides, including a built-in limit: The number of virtual hosts that can be supported depends on how many IP addresses you have available. Each virtual host requires its own unique IP address. This requirement made it easy for an ISP to swallow up scarce IP addresses with only a few customers.

<BR>

<P>In the current incarnation of the server, the Apache group introduced a non&#150;IP-intensive solution. Using a new extension to the HTTP protocol, which requires the browser to report the name of the server being accessed (the http://www.apple.com portion of the URL) along with the resource to retrieve, the Web server can determine who the request is for. Before, an URL such as http://www.apple.com/index.html would have the www.apple.com portion removed from the request, making it impossible for the server to determine the name of the host as known by the user. This new mechanism effectively added the infrastructure from which Apache could provide virtual site support without the need to create a multihomed computer. Non&#150;IP-intensive virtual hosts make it possible to host an almost infinite number of virtual hosts easily, without the need to create a multihomed server.

<BR>

<BR>

<A NAME="E68E31"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>The </B><B>&lt;VirtualHost&gt;</B><B> Directive</B><B> Section</B></FONT></CENTER></H3>

<BR>

<P>The &lt;VirtualHost&gt; and &lt;/VirtualHost&gt; section tags are used to group server configuration directives that only apply to a particular virtual host. Any directive that is allowed in a virtual host context can be used. When the server receives a request directed toward a virtual host, the configuration directives enclosed between the &lt;VirtualHost&gt; and &lt;/VirtualHost&gt; section tags override directives found elsewhere. &lt;VirtualHost&gt; sections are found in the httpd.conf file.

<BR>

<P>You specify the host to which a &lt;VirtualHost&gt; section applies by specifying the IP of the virtual host or a fully qualified domain name. A minimal virtual host only needs to override the DocumentRoot directive:

<BR>

<PRE>

<FONT COLOR="#000080">&lt;VirtualHost www.company.com&gt;

DocumentRoot /www/docs/company

&lt;/VirtualHost&gt;</FONT></PRE>

<P>The &lt;VirtualHost&gt; declaration&gt; for non&#150;IP-intensive virtual hosts, based on the HTTP/1.1 feature previously described , is almost identical to the original IP-intensive version, except that you only supply a machine name that resolves to the same IP address as the real host. The server decides what to serve based on the machine name used to access the resource.

<BR>

<P>This approach only works with browsers that comply to the HTTP/1.1 specification, which is still a draft.. Hopefully this will become part of the specification and will be more widely implemented.

<BR>

<P>For IP-intensive virtual hosts, each host IP identified by the &lt;VirtualHost&gt; directive must be unique and, in order for it to work, the computer must be configured to accept multiple IP addresses. This configuration, unlike that of the new non-IP virtual hosts, works regardless of the browser.

<BR>

<P>The &lt;VirtualHost&gt; section allows configuration of a virtual host as if it were a simple single-homed server; it allows you to implement customized server configuration settings on a per-site basis. Each site can tailor the server to its own needs.

<BR>

<P>A minimal virtual host configuration only needs to make use of the DocumentRoot directive. You can further customize the virtual server with ServerName directives, which will set the name the server will use when responding to requests. You are able to include many of the directives that can be specified in the server configuration file (httpd.conf) or in the resource configuration file (srm.conf). This gives total control over the configuration and behavior of the virtual server. You can even enable logging of the transaction to different log files. The following configuration presents a more complete and typical example:

<BR>

<PRE>

<FONT COLOR="#000080">#### Virtual machine configuration

#Bind Address (Address identifying this virtual host

BindAddress *

&lt;VirtualHost&gt;

#

#Server name returned to users connected to this host

ServerName www.company.com

#

#

#WebMaster for this host

#IF YOU USE A VIRTUAL DOMAIN FOR MAIL, REMEMBER TO

#CONFIGURE SENDMAIL TO ACCEPT THIS DOMAIN IN YOUR SENDMAIL.CF!!!

#

ServerAdmin webmaster@company.com

#

#The document root for this virtual host

DocumentRoot /usr/local/etc/htdocs/company.htmld 

#

#The location of the error log for the virtual host

ErrorLog /usr/local/etc/apache/logs/company/error_log

#

#The location of the access log for the virtual host

TransferLog /usr/local/etc/apache/logs/company/access_log

...

&lt;/VirtualHost&gt;

#### End Virtual Machine configuration</FONT></PRE>

<P>Configuration using&gt; the &lt;VirtualHost&gt; directive is, as you can see, pretty straightforward. However, there are some mechanics that must be resolved prior to getting a server to multihome (namely, how to configure the server so that it answers to different IP numbers).

<BR>

<BR>

<A NAME="E69E24"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>BindAddress</B></FONT></CENTER></H4>

<BR>

<P>The BindAddress directive allows you to further refine where the server will listen for connections. The default behavior for the server is to listen for requests on all the IP addresses supported on the machine (BindAddress *) at the port specified by the Port directive. However, this may not be what you want. You may want to limit which addresses the server will serve. The BindAddress directive allows you to specify this. BindAddress allows you to specify the addresses to listen for (either the IP address or fully qualified hostname). These are examples for the various possibilities:

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">BindAddress 1.2.3.4</FONT></PRE>

<P>Or this specifies the fully qualified name of the machine:

<BR>

<BR>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -