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

📄 mass.html.en

📁 Apache2.2.4 with OpenSSL 0.9.8e 提供HTTP及HTTPS服务。 带QuickUsage
💻 EN
📖 第 1 页 / 共 2 页
字号:
&lt;/Directory&gt;<br />
<br />
&lt;Directory /www/homepages&gt;<br />
<span class="indent">
    Options FollowSymLinks<br />
    AllowOverride None<br />
</span>
&lt;/Directory&gt;<br />
<br />
&lt;VirtualHost 111.22.33.44&gt;<br />
<span class="indent">
    ServerName www.commercial.isp.com<br />
    <br />
    CustomLog logs/access_log.commercial vcommon<br />
    <br />
    VirtualDocumentRoot /www/commercial/%0/docs<br />
    VirtualScriptAlias  /www/commercial/%0/cgi-bin<br />
</span>
&lt;/VirtualHost&gt;<br />
<br />
&lt;VirtualHost 111.22.33.45&gt;<br />
<span class="indent">
    ServerName www.homepages.isp.com<br />
    <br />
    CustomLog logs/access_log.homepages vcommon<br />
    <br />
    VirtualDocumentRoot /www/homepages/%0/docs<br />
    ScriptAlias         /cgi-bin/ /www/std-cgi/<br />
</span>
&lt;/VirtualHost&gt;
</code></p></div>

</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="ipbased" id="ipbased">More efficient IP-based virtual hosting</a></h2>

    <p>After <a href="#simple">the first example</a> I noted that
    it is easy to turn it into an IP-based virtual hosting setup.
    Unfortunately that configuration is not very efficient because
    it requires a DNS lookup for every request. This can be avoided
    by laying out the filesystem according to the IP addresses
    themselves rather than the corresponding names and changing the
    logging similarly. Apache will then usually not need to work
    out the server name and so incur a DNS lookup.</p>

<div class="example"><p><code>
# get the server name from the reverse DNS of the IP address<br />
UseCanonicalName DNS<br />
<br />
# include the IP address in the logs so they may be split<br />
LogFormat "%A %h %l %u %t \"%r\" %s %b" vcommon<br />
CustomLog logs/access_log vcommon<br />
<br />
# include the IP address in the filenames<br />
VirtualDocumentRootIP /www/hosts/%0/docs<br />
VirtualScriptAliasIP  /www/hosts/%0/cgi-bin<br />
</code></p></div>

</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="oldversion" id="oldversion">Using older versions of Apache</a></h2>

    <p>The examples above rely on <code>mod_vhost_alias</code>
    which appeared after version 1.3.6. If you are using a version
    of Apache without <code>mod_vhost_alias</code> then you can
    implement this technique with <code>mod_rewrite</code> as
    illustrated below, but only for Host:-header-based virtual
    hosts.</p>

    <p>In addition there are some things to beware of with logging.
    Apache 1.3.6 is the first version to include the
    <code>%V</code> log format directive; in versions 1.3.0 - 1.3.3
    the <code>%v</code> option did what <code>%V</code> does;
    version 1.3.4 has no equivalent. In all these versions of
    Apache the <code>UseCanonicalName</code> directive can appear
    in <code>.htaccess</code> files which means that customers can
    cause the wrong thing to be logged. Therefore the best thing to
    do is use the <code>%{Host}i</code> directive which logs the
    <code>Host:</code> header directly; note that this may include
    <code>:port</code> on the end which is not the case for
    <code>%V</code>.</p>

</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="simple.rewrite" id="simple.rewrite">Simple dynamic
    virtual hosts using <code>mod_rewrite</code></a></h2>

    <p>This extract from <code>httpd.conf</code> does the same
    thing as <a href="#simple">the first example</a>. The first
    half is very similar to the corresponding part above but with
    some changes for backward compatibility and to make the
    <code>mod_rewrite</code> part work properly; the second half
    configures <code>mod_rewrite</code> to do the actual work.</p>

    <p>There are a couple of especially tricky bits: By default,
    <code>mod_rewrite</code> runs before the other URI translation
    modules (<code>mod_alias</code> etc.) so if they are used then
    <code>mod_rewrite</code> must be configured to accommodate
    them. Also, some magic must be performed to do a
    per-dynamic-virtual-host equivalent of
    <code>ScriptAlias</code>.</p>

<div class="example"><p><code>
# get the server name from the Host: header<br />
UseCanonicalName Off<br />
<br />
# splittable logs<br />
LogFormat "%{Host}i %h %l %u %t \"%r\" %s %b" vcommon<br />
CustomLog logs/access_log vcommon<br />
<br />
&lt;Directory /www/hosts&gt;<br />
<span class="indent">
    # ExecCGI is needed here because we can't force<br />
    # CGI execution in the way that ScriptAlias does<br />
    Options FollowSymLinks ExecCGI<br />
</span>
&lt;/Directory&gt;<br />
<br />
# now for the hard bit<br />
<br />
RewriteEngine On<br />
<br />
# a ServerName derived from a Host: header may be any case at all<br />
RewriteMap  lowercase  int:tolower<br />
<br />
## deal with normal documents first:<br />
# allow Alias /icons/ to work - repeat for other aliases<br />
RewriteCond  %{REQUEST_URI}  !^/icons/<br />
# allow CGIs to work<br />
RewriteCond  %{REQUEST_URI}  !^/cgi-bin/<br />
# do the magic<br />
RewriteRule  ^/(.*)$  /www/hosts/${lowercase:%{SERVER_NAME}}/docs/$1<br />
<br />
## and now deal with CGIs - we have to force a MIME type<br />
RewriteCond  %{REQUEST_URI}  ^/cgi-bin/<br />
RewriteRule  ^/(.*)$  /www/hosts/${lowercase:%{SERVER_NAME}}/cgi-bin/$1  [T=application/x-httpd-cgi]<br />
<br />
# that's it!
</code></p></div>

</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="homepages.rewrite" id="homepages.rewrite">A
    homepages system using <code>mod_rewrite</code></a></h2>

    <p>This does the same thing as <a href="#homepages">the second
    example</a>.</p>

<div class="example"><p><code>
RewriteEngine on<br />
<br />
RewriteMap   lowercase  int:tolower<br />
<br />
# allow CGIs to work<br />
RewriteCond  %{REQUEST_URI}  !^/cgi-bin/<br />
<br />
# check the hostname is right so that the RewriteRule works<br />
RewriteCond  ${lowercase:%{SERVER_NAME}}  ^www\.[a-z-]+\.isp\.com$<br />
<br />
# concatenate the virtual host name onto the start of the URI<br />
# the [C] means do the next rewrite on the result of this one<br />
RewriteRule  ^(.+)  ${lowercase:%{SERVER_NAME}}$1  [C]<br />
<br />
# now create the real file name<br />
RewriteRule  ^www\.([a-z-]+)\.isp\.com/(.*) /home/$1/$2<br />
<br />
# define the global CGI directory<br />
ScriptAlias  /cgi-bin/  /www/std-cgi/
</code></p></div>

</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="xtra-conf" id="xtra-conf">Using a separate virtual
    host configuration file</a></h2>

    <p>This arrangement uses more advanced <code>mod_rewrite</code>
    features to get the translation from virtual host to document
    root from a separate configuration file. This provides more
    flexibility but requires more complicated configuration.</p>

    <p>The <code>vhost.map</code> file contains something like
    this:</p>

<div class="example"><p><code>
www.customer-1.com  /www/customers/1<br />
www.customer-2.com  /www/customers/2<br />
# ...<br />
www.customer-N.com  /www/customers/N<br />
</code></p></div>

    <p>The <code>http.conf</code> contains this:</p>

<div class="example"><p><code>
RewriteEngine on<br />
<br />
RewriteMap   lowercase  int:tolower<br />
<br />
# define the map file<br />
RewriteMap   vhost      txt:/www/conf/vhost.map<br />
<br />
# deal with aliases as above<br />
RewriteCond  %{REQUEST_URI}               !^/icons/<br />
RewriteCond  %{REQUEST_URI}               !^/cgi-bin/<br />
RewriteCond  ${lowercase:%{SERVER_NAME}}  ^(.+)$<br />
# this does the file-based remap<br />
RewriteCond  ${vhost:%1}                  ^(/.*)$<br />
RewriteRule  ^/(.*)$                      %1/docs/$1<br />
<br />
RewriteCond  %{REQUEST_URI}               ^/cgi-bin/<br />
RewriteCond  ${lowercase:%{SERVER_NAME}}  ^(.+)$<br />
RewriteCond  ${vhost:%1}                  ^(/.*)$<br />
RewriteRule  ^/(.*)$                      %1/cgi-bin/$1
</code></p></div>

</div></div>
<div class="bottomlang">
<p><span>Available Languages: </span><a href="../en/vhosts/mass.html" title="English">&nbsp;en&nbsp;</a> |
<a href="../ko/vhosts/mass.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a></p>
</div><div id="footer">
<p class="apache">Copyright 2006 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
<p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div>
</body></html>

⌨️ 快捷键说明

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