Debian Codegraph @

doc/howto/Vhost.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>ProFTPD: Virtual Servers</title>
5 </head>
6
7 <body bgcolor=white>
8
9 <hr>
10 <center><h2><b>ProFTPD: Virtual Servers</b></h2></center>
11 <hr>
12
13 <p><a name="Definition"></a>
14 <b>What is a virtual server?</b><br>
15 A virtual server, also known as a virtual host (or <i>vhost</i> for short),
16 refers to the practice of serving more than one address/site on a single host
17 machine. The fact that these multiple sites are being served by the same
18 physical machine is transparent to the end user.
19
20 <p>
21 Until very recently, the definition of FTP did not allow for <i>name</i>-based
22 virtual hosts, such as supported by HTTP/1.1. That changed with
23 <a href="https://tools.ietf.org/html/rfc7151">RFC 7151</a>, which defined a
24 <code>HOST</code> FTP command. ProFTPD virtual hosts are IP-based <i>and</i>
25 name-based.
26
27 <p>
28 In some documents, one might see reference to both &quot;daemon&quot; and
29 &quot;server&quot;. Sometimes these words are used interchangeably; however,
30 there is a slight difference. A &quot;daemon&quot; is a long-lived process
31 on a host machine, and a &quot;server&quot; is a process that provides some
32 service, typically to remote clients. A process, such as a standalone
33 <code>proftpd</code> process, can be considered both a &quot;daemon&quot;
34 and a &quot;server&quot;. With this in mind, then, a &quot;virtual server&quot;
35 is not a separate process itself; it just looks like one to the remote clients.
36 Hence the &quot;virtual&quot;.
37
38 <p><a name="Configuration"></a>
39 There are three &quot;server&quot; contexts (sometimes also called
40 <i>sections</i>) in the <code>proftpd.conf</code> configuration file:
41 <a href="../modules/mod_core.html#VirtualHost"><code>&lt;VirtualHost&gt;</code></a>, <a href="../modules/mod_core.html#Global"><code>&lt;Global&gt;</code></a>,
42 and &quot;server config&quot;.
43
44 <p>
45 The <code>&lt;VirtualHost&gt;</code> context is used to define the configuration
46 for a particular virtual host, bound to an IP address. For example:
47 <pre>
48 &lt;VirtualHost 1.2.3.4&gt;
49 ...
50 &lt;/VirtualHost&gt;
51 </pre>
52 defines a configuration for a virtual server that <code>proftpd</code> should
53 use whenever a remote client connects to the IP address 1.2.3.4. DNS names,
54 too, can be used with the <code>&lt;VirtualHost&gt;</code> configuration
55 directive:
56 <pre>
57 &lt;VirtualHost ftp.mydomain.com&gt;
58 ...
59 &lt;/VirtualHost&gt;
60 </pre>
61 When <code>proftpd</code> parses this section on startup, it will resolve the
62 given DNS name to its IP address and use that, just as if that IP address
63 had been used in the first place. In addition, when DNS names are used like
64 this, ProFTPD will <i>automatically</i> create a <a href="../modules/mod_core.html#ServerAlias"><code>ServerAlias</code></a> directive using that DNS name.
65 This allows for multiple <code>&lt;VirtualHost&gt;</code> sections using the
66 same DNS name to be defined in your <code>proftpd.conf</code>.
67
68 <p>
69 If you want the same vhost to be used for multiple different names at the
70 same time (<i>e.g.</i> because you have multiple DNS names for the same
71 server), you would use the <code>ServerAlias</code> directive to list those
72 other names, like so:
73 <pre>
74 &lt;VirtualHost ftp.mydomain.com&gt;
75 # Use this vhost for other names, too
76 ServerAlias ftp.mydomain.org ftp2.mydomain.com ftp.otherdomain.org
77 ...
78 &lt;/VirtualHost&gt;
79 </pre>
80
81 <p>
82 The <code>&lt;Global&gt;</code> section is provided as a convenience. Imagine
83 that the administrator has many <code>&lt;VirtualHost&gt;</code> sections
84 in her <code>proftpd.conf</code>, and yet has a lot of the same configuration
85 for each virtual host, such as common <code>&lt;Directory&gt;</code> sections,
86 <code>DefaultRoot</code> settings, <i>etc</i>. Rather than including the
87 same configuration over and over, she could use the <code>&lt;Global&gt;</code>
88 section:
89 <pre>
90 &lt;Global&gt;
91 ...
92 &lt;/Global&gt;
93 </pre>
94 Anything inside of a <code>&lt;Global&gt;</code> section is applied to every
95 server configuration in the file, to every <code>&lt;VirtualHost&gt;</code> as
96 well as the default &quot;server config&quot; server.
97
98 <p>
99 Which brings us to the &quot;server config&quot; section. The name is
100 ill-suited, and is really borrowed directly from Apache's naming conventions.
101 The &quot;server config&quot; context refers to anything <b>not</b> in a
102 <code>&lt;VirtualHost&gt;</code> or <code>&lt;Global&gt;</code> section in
103 the <code>proftpd.conf</code> file. Unlike Apache's <code>httpd.conf</code>,
104 ProFTPD's configuration is designed such that one should be able to use
105 the simplest file as possible. In fact, <code>proftpd</code> will start
106 if the <code>proftpd.conf</code> is completely empty; try it! This will
107 cause the daemon to use all of the default settings, which in most cases
108 is not what is wanted, but it <i>is</i> possible. With this in mind,
109 there is always at least <i>one</i> server configuration present: the default
110 server context, and it is this context that is known as the
111 &quot;server config&quot;. Just like the <code>&lt;VirtualHost&gt;</code>
112 section, any configuration directives inside the &quot;server config&quot;
113 section <b>do not apply</b> outside of the context. Many administrators often
114 <i>assume</i> that this is the case. It is not. This is what the
115 <code>&lt;Global&gt;</code> section is for.
116
117 <p>
118 However, one particular drawback to the &quot;server config&quot; section was
119 that it did not provide a way to specify to which IP address that configuration
120 pertained. By default, when <code>proftpd</code> parses the
121 <code>proftpd.conf</code> file, it will use the <code>gethostname()</code>
122 function to determine the IP address to which the default server should listen.
123 On a single address, single interface system, this default is fine. It is one
124 a multiple address system that the default handling does not always work;
125 the administrator may wish to explicitly specify to which address the default
126 server should listen. This is what the <a href="../modules/mod_core.html#DefaultAddress"><code>DefaultAddress</code></a> configuration directive provides: the
127 ability to specify to which IP address the &quot;server config&quot; vhost
128 should listen.
129
130 <p>
131 By default, every server will listen to port 21, the IANA standard port for
132 FTP. If you want to have server react to a different port, use the
133 <a href="../modules/mod_core.html#Port"><code>Port</code></a> directive to
134 change the port. As might be mentioned elsewhere, if you have many different
135 <code>&lt;VirtualHost&gt;</code> sections using the <i>same address</i> but
136 different <i>ports</i>, you'll want to make sure that you leave each
137 <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
138 data transfer (read <a href="http://slacksite.com/other/ftp.html">here</a>)
139 must be <code>L-1</code>, where <code>L</code> is the port on which your server
140 listens. Also, as mentioned in the <code>Port</code> documentation, using:
141 <pre>
142 Port 0
143 </pre>
144 in any server context will effectively &quot;disable&quot; that server. This
145 is sometimes used to disable the &quot;server config&quot; configuration.
146
147 <p>
148 There is another configuration directive that comes into play in all of this
149 : <a href="../modules/mod_core.html#DefaultServer"><code>DefaultServer</code></a>. Here is why: when a client contacts <code>proftpd</code>, the server has to
150 determine which configuration to use for handling the client. To do this, it
151 searches its list of configured vhosts, searching for a vhost whose IP address
152 matches the IP address that the client contacted. If there is a matching vhost
153 for that IP address, simple: use that configuration. If not,
154 <code>proftpd</code> will then resort to using the configuration that bears the
155 <code>DefaultServer</code> directive, which says that the server configuration
156 in which it appears should be used in cases like this. If there is no
157 <code>DefaultServer</code> directive in the <code>proftpd.conf</code> file,
158 and no matching configuration can be found, then the client will see a message
159 such as &quot;no server available to service your request&quot;. The
160 <code>DefaultServer</code> can be used to say that a
161 <code>&lt;VirtualHost&gt;</code> should be the default, and not necessarily the
162 &quot;server config&quot; context, as is common.
163
164 <p>
165 If you would like the same virtual host configuration to be used for
166 multiple different IP addresses (or DNS names), the
167 <code>&lt;VirtualHost&gt;</code> supports this:
168 <pre>
169 &lt;VirtualHost 1.2.3.4 5.6.7.8&gt;
170 ...
171 &lt;/VirtualHost&gt;
172 </pre>
173
174 <p>
175 If, however, you want to specific the address to which the configuration
176 of the &quot;server config&quot; context, use <code>DefaultAddress</code>
177 (mentioned above).
178
179 <p>
180 There is one last configuration directive about which an administrator should
181 know: <a href="../modules/mod_core.html#SocketBindTight"><code>SocketBindTight</code></a>. By default, the
182 <code>proftpd</code> daemon will listen on all addresses, port 21, for the
183 connection requests of remote clients. Sometimes, the administrator may
184 wish to have the <code>proftpd</code> daemon listen <b>only</b> on the IP
185 addresses for which it has been configured, and not <i>every</i> address.
186 To accomplish this, simply use the <code>SocketBindTight</code> configuration
187 directive:
188 <pre>
189 SocketBindTight on
190 </pre>
191 This configures the daemon to &quot;bind tightly&quot; only to those IP
192 addresses to which it has been configured to listen, rather than every address.
193 By default, the <code>proftpd</code> daemon will listen to every address on
194 the host machine.
195
196 <p><a name="FAQ"></a>
197 <b>Frequently Asked Questions</b><br>
198
199 <p>
200 <font color=red>Question</font>: Why do I see the following when I start <code>proftpd</code>?<br>
201 <pre>
202 - warning: "Virtual Server" address/port (1.2.3.4:21) already in use by "Main Server"
203 </pre>
204 <font color=blue>Answer</font>: This happens when a <code>&lt;VirtualHost&gt;</code> section is "hidden" behind the default server in the "server config"
205 section (<i>i.e.</i> the context that is outside of all <code>&lt;VirtualHost&gt;</code> and <code>&lt;Global&gt;</code> sections). It is "hidden" because
206 both the <code>&lt;VirtualHost&gt;</code> section and the "server config"
207 section are using the same IP address and port.
208
209 <p>
210 It is quite common to configure <code>&lt;VirtualHost&gt;</code> sections
211 using DNS names, rather than IP addresses. And the "server config" section
212 in the <code>proftpd.conf</code> file, by default, uses the IP address of
213 the machine's hostname. This makes it quite easy to inadvertently have
214 multiple sections trying to use the same IP address and port.
215
216 <p>
217 The quick-and-easy fix is to place the following your "server config" section
218 in your <code>proftpd.conf</code>:
219 <pre>
220 Port 0
221 </pre>
222 as mentioned above. You can also use the <code>DefaultAddress</code>
223 directive in the "server config" section to explicitly tell the "server config"
224 section to use a different IP address/DNS name.
225
226 <p>
227 <font color=red>Question</font>: How can I have my "server config" section
228 (or a <code>&lt;VirtualHost&gt;</code> section) listen for multiple IP
229 addresses/DNS names?<br>
230 <font color=blue>Answer</font>: In version 1.3.0rc1 and later, the
231 <code>&lt;VirtualHost&gt;</code> configuration was enhanced so that it could
232 handle multiple IP addresses/DNS names, <i>e.g.</i>:
233 <pre>
234 &lt;VirtualHost 1.2.3.4 ftp.example.com&gt;
235 ...
236 &lt;/VirtualHost&gt;
237 </pre>
238 And for the "server config" context, you would use the
239 <code>DefaultAddress</code> directive, which can also handle multiple IP
240 addresses/DNS names:
241 <pre>
242 DefaultAddress 1.2.3.4 ftp.example.com
243 </pre>
244
245 <p>
246 <font color=red>Question</font>: If I want to use many virtual hosts, do I
247 need to use a different port for each virtual host, or can the same port be
248 reused?<br>
249 <font color=blue>Answer</font>: The short answer is yes, it is possible to
250 have many virtual hosts on the same IP address and port.
251
252 <p>
253 However, doing so requires support from clients to work as you expect.
254 Specifically, it requires that FTP clients send the <code>HOST</code> command
255 (defined in
256 <a href="https://datatracker.ietf.org/doc/html/rfc7151">RFC 7151</a>), and not
257 all FTP clients do so. This command is equivalent to HTTP's <code>Host</code>
258 header, but it is newer, and so not every FTP client implementation has been
259 updated to use it. Without that <code>HOST</code> command, ProFTPD only has
260 the IP address/port combination from a client TCP connection to use for
261 determining which virtual host to use, and if there are many virtual hosts
262 (differentiated only by <em>name</em>) using the same IP address and port,
263 then ProFTPD cannot tell which specific virtual host to use. It will not work
264 as you expect, for clients that do not use the <code>HOST</code> command.
265
266 <p>
267 <hr>
268 <font size=2><b><i>
269 &copy; Copyright 2017-2023 The ProFTPD Project<br>
270 All Rights Reserved<br>
271 </i></b></font>
272 <hr>
273
274 </body>
275 </html>