Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 976aeacbdb50a0541a053b760df66615 > files > 110

proftpd-1.3.1-11mdv2008.1.x86_64.rpm

<!-- $Id: Vhost.html,v 1.5 2007/09/12 18:08:19 castaglia Exp $ -->
<!-- $Source: /cvsroot/proftp/proftpd/doc/howto/Vhost.html,v $ -->

<html>
<head>
<title>ProFTPD mini-HOWTO - Virtual Servers</title>
</head>

<body bgcolor=white>

<hr>
<center><h2><b>ProFTPD and Virtual Servers</b></h2></center>
<hr>

<p><a name="Definition"></a>
<b>What is a virtual server?</b><br>
A virtual server, also known as a virtual host (or <i>vhost</i> for short),
refers to the practice of serving more than one address/site on a single host
machine.  The fact that these multiple sites are being served by the same
physical machine is transparent to the end user.

<p>
The definition of the File Transfer Protocol, unfortunately, does not
(currently) support name-based virtual hosts, as HTTP1.1 supports.  All FTP
virtual hosts are based on unique IP address/port combinations, not on DNS
names.  The similarity of ProFTPD's configuration file syntax to Apache's
sometimes leads users to assuming that <code>proftpd</code> will handle these
the same way -- but more on this later.  The bottom line is that ProFTPD
does not support name-based virtual hosts; not because they are not implemented,
but simply because the protocol itself does not support them.

<p>
In some documents, one might see reference to both &quot;daemon&quot; and
&quot;server&quot;.  Sometimes these words are used interchangeably; however,
there is a slight difference.  A &quot;daemon&quot; is a long-lived process
on a host machine, and a &quot;server&quot; is a process that provides some
service, typically to remote clients.  A process, such as a standalone
<code>proftpd</code> process, can be considered both a &quot;daemon&quot;
and a &quot;server&quot;.  With this in mind, then, a &quot;virtual server&quot;
is not a separate process itself; it just looks like one to the remote clients.
Hence the &quot;virtual&quot;.

<p><a name="Configuration"></a>
There are three &quot;server&quot; contexts (sometimes also called
<i>sections</i>) in the <code>proftpd.conf</code> configuration file:
<a href="http://www.proftpd.org/docs/directives/linked/config_ref_VirtualHost.html"><code>&lt;VirtualHost&gt;</code></a>, <a href="http://www.proftpd.org/docs/directives/linked/config_ref_Global.html"><code>&lt;Global&gt;</code></a>, and &quot;server config&quot;.

<p>
The <code>&lt;VirtualHost&gt;</code> context is used to define the configuration
for a particular virtual host, bound to an IP address.  For example:
<pre>
  &lt;VirtualHost 1.2.3.4&gt;
    ...
  &lt;/VirtualHost&gt;
</pre>
defines a configuration for a virtual server that <code>proftpd</code> should
use whenever a remote client connects to the IP address 1.2.3.4.  DNS names,
too, can be used with the <code>&lt;VirtualHost&gt;</code> configuration
directive, and this is where some of the name-based vhost support confusion
creeps in:
<pre>
  &lt;VirtualHost ftp.mydomain.com&gt;
    ...
  &lt;/VirtualHost&gt;
</pre>
When <code>proftpd</code> parses this context on startup, it will resolve the
given DNS name to its IP address and use that, just as if that IP address
had been used in the first place.  Use of DNS names like this, while convenient,
can easily lead to confusion when multiple DNS names resolve to the same
IP address.  If this happens, <code>proftpd</code> will use the first
context in the configuration file when serving that address.

<p>
The <code>&lt;Global&gt;</code> context is provided as a convenience.  Imagine
that the administrator has many <code>&lt;VirtualHost&gt;</code> contexts
in her <code>proftpd.conf</code>, and yet has a lot of the same configuration
for each virtual host, such as common <code>&lt;Directory&gt;</code> sections,
<code>DefaultRoot</code> settings, <i>etc</i>.  Rather than including the
same configuration over and over, she could use the <code>&lt;Global&gt;</code>
context:
<pre>
  &lt;Global&gt;
    ...
  &lt;/Global&gt;
</pre>
Anything inside of a <code>&lt;Global&gt;</code> section is applied to every
server configuration in the file, to every <code>&lt;VirtualHost&gt;</code> as
well as the default &quot;server config&quot; server.

<p>
Which brings us to the &quot;server config&quot; context.  The name is
ill-suited, and is really borrowed directly from Apache's naming conventions.
The &quot;server config&quot; context refers to anything not in a
<code>&lt;VirtualHost&gt;</code> or <code>&lt;Global&gt;</code> context in
the <code>proftpd.conf</code> file.  Unlike Apache's <code>httpd.conf</code>,
ProFTPD's configuration is designed such that one should be able to use
the simplest file as possible.  In fact, <code>proftpd</code> will start
if the <code>proftpd.conf</code> is completely empty; try it!  This will
cause the daemon to use all of the default settings, which in most cases
is not what is wanted, but it <i>is</i> possible.  With this in mind,
there is always at least one server configuration present: the default server
context, and it is this context that is known as the &quot;server config&quot;.
Just like the <code>&lt;VirtualHost&gt;</code> context, any configuration
directives inside the &quot;server config&quot; context <b>do not apply</b>
outside of the context.  Many administrators often assume that this is the
case.  It is not.  This is what the <code>&lt;Global&gt;</code> context
is for.

<p>
However, one particular drawback to the &quot;server config&quot; context was
that it did not provide a way to specify to which IP address that configuration
pertained.  By default, when <code>proftpd</code> parses the
<code>proftpd.conf</code> file, it will use the <code>gethostname()</code>
function to determine the IP address to which the default server should listen.
On a single address, single interface system, this default is fine. It is one
a multiple address system that the default handling does not always work;
the administrator may wish to explicitly specify to which address the default
server should listen.  This is what the <a href="http://www.proftpd.org/docs/directives/linked/config_ref_DefaultAddress.html"><code>DefaultAddress</code></a>
configuration directive provides: the ability to specify to which IP address
the &quot;server config&quot; vhost should listen.

<p>
By default, every server will listen to port 21, the IANA standard port for
FTP.  If you want to have server react to a different port, use the
<a href="http://www.proftpd.org/docs/directives/linked/config_ref_Port.html"><code>Port</code></a> directive to change the port.  As might be mentioned
elsewhere, if you have many different <code>&lt;VirtualHost&gt;</code> contexts
using the same address but different ports, you'll want to make sure that
you leave each <code>Port</code>-1 number empty.  <a href="http://www.faqs.org/rfcs/rfc959.html">RFC 959</a> specifies that the source port for an active
data transfer (read <a href="http://slacksite.com/other/ftp.html">here</a>)
must be <code>L-1</code>, where <code>L</code> is the port on which your server
listens.  Also, as mentioned in the <code>Port</code> documentation, using:
<pre>
  Port 0
</pre>
in any server context will effectively &quot;disable&quot; that server.  This
is sometimes used to disable the &quot;server config&quot; configuration.

<p>
There is another configuration directive that comes into play in all of this
: <a href="http://www.proftpd.org/docs/directives/linked/config_ref_DefaultServer.html"><code>DefaultServer</code></a>.  Here is why: when a client
contacts <code>proftpd</code>, the server has to determine which configuration
to use for handling the client.  To do this, it searches its list of configured
vhosts, searching for a vhost whose IP address matches the IP address that the
client contacted.  If there's a matching vhost for that IP address, simple:
use that configuration.  If not, <code>proftpd</code> will then resort to
using the configuration that bears the <code>DefaultServer</code> directive,
which says that the server configuration in which it appers should be used
in cases like this.  If there is no <code>DefaultServer</code> directive
in the <code>proftpd.conf</code> file, and no matching configuration can
be found, then the client will see a message such as &quot;no server available
to service your request&quot;.  The <code>DefaultServer</code> can be
used to say that a <code>&lt;VirtualHost&gt;</code> should be the default,
and not necessarily the &quot;server config&quot; context, as is common.

<p>
If you would like the same virtual host configuration to be used for
multiple different IP addresses (or DNS names), the
<code>&lt;VirtualHost&gt;</code> supports this:
<pre>
  &lt;VirtualHost 1.2.3.4 5.6.7.8&gt;
    ...
  &lt;/VirtualHost&gt;
</pre>

<p>
If, however, you want to specific the address to which the configuration
of the &quot;server config&quot; context, use <code>DefaultAddress</code>
(mentioned above).

<p>
There is one last configuration directive about which an administrator should
know: <a href="http://www.proftpd.org/docs/directives/linked/config_ref_SocketBindTight.html"><code>SocketBindTight</code></a>.  By default, the
<code>proftpd</code> daemon will listen on all addresses, port 21, for the
connection requests of remote clients.  Sometimes, the administrator may
wish to have the <code>proftpd</code> daemon listen <b>only</b> on the IP
addresses for which it has been configured, and not <i>every</i> address.
To accomplish this, simply use the <a href="http://www.proftpd.org/docs/directives/linked/config_ref_SocketBindTight.html"><code>SocketBindTight</code></a> configuration directive:
<pre>
  SocketBindTight on
</pre>
This configures the daemon to &quot;bind tightly&quot; only to those IP
addresses to which it has been configured to listen, rather than every address.
By default, the <code>proftpd</code> daemon will listen to every address on
the host machine.

<p>
<hr>
Last Updated: <i>$Date: 2007/09/12 18:08:19 $</i><br>
<hr>

</body>
</html>