summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/doc/configure/file_directives.html
blob: a5ec2c68357f0268f6fc76ee522e183cdb82f69b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
<base href="../" />

<!-- oktavia -->
<link rel="stylesheet" href="assets/searchstyle.css" type="text/css" />
<script src="search/jquery-1.9.1.min.js"></script>
<script src="search/oktavia-jquery-ui.js"></script>
<script src="search/oktavia-english-search.js"></script>
<!-- /oktavia -->

<link rel="stylesheet" href="assets/style.css" type="text/css" />

<title>File Directives - Configure - H2O - the optimized HTTP/2 server</title>
</head>
<body>
<div id="body">
<div id="top">

<h1>
<a href="index.html">H2O</a>
</h1>
<p class="description">the optimized HTTP/1.x, HTTP/2 server</p>

<!-- oktavia -->
<form id="searchform">
<input class="search" type="search" name="search" id="search" results="5" value="" placeholder="Search" />
<div id="searchresult_box">
<div id="close_search_box">&times;</div>
<div id="searchresult_summary"></div>
<div id="searchresult"></div>
<div id="searchresult_nav"></div>
<span class="pr">Powered by <a href="https://github.com/shibukawa/oktavia">Oktavia</a></span>
</div>
</form>
<!-- /oktavia -->

</div>

<table id="menu">
<tr>
<td><a href="index.html">Top</a></td>
<td><a href="install.html">Install</a></td>
<td class="selected">Configure</td>
<td><a href="faq.html">FAQ</a></td>
<td><a href="http://blog.kazuhooku.com/search/label/H2O" target="_blank">Blog</a></td>
<td><a href="http://github.com/h2o/h2o/" target="_blank">Source</a></td>
</tr>
</table>

<div id="main">

<h2>
<a href="configure.html">Configure</a> &gt;
File Directives
</h2>


<p>
This document describes the configuration directives of the file handler - a handler that for serving static files.
</p>
<p>
Two directives: <a href="configure/file_directives.html#file.dir"><code>file.dir</code></a> and <a href="configure/file_directives.html#file.file"><code>file.file</code></a> are used to define the mapping.
Other directives modify the behavior of the mappings defined by the two.
</p>

<div id="file.custom-handler" class="directive-head">
<h3><a href="configure/file_directives.html#file.custom-handler"><code>"file.custom-handler"</code></a></h3>
</div>

<dl class="directive-desc">
<dt>Description:</dt>
<dd>
<p>
The directive maps extensions to a custom handler (e.g. FastCGI).
</p>

<p>
The directive accepts a mapping containing configuration directives that can be used at the <code>extension</code> level, together with a property named <code>extension</code> specifying a extension (starting with <code>.</code>) or a sequence of extensions to which the directives should be applied.
Only one handler must exist within the directives.
</p>
<div class="example">
<div class="caption">Example. Mapping PHP files to FastCGI</div>
<pre><code>file.custom-handler:
  extension: .php
  fastcgi.connect:
    port: /tmp/fcgi.sock
    type: unix

</code></pre>
</div>


</dd>
<dt><a href="configure/syntax_and_structure.html#config_levels">Level</a>:</dt>
<dd>global, host, path</dd>
</dl>

<div id="file.dir" class="directive-head">
<h3><a href="configure/file_directives.html#file.dir"><code>"file.dir"</code></a></h3>
</div>

<dl class="directive-desc">
<dt>Description:</dt>
<dd>
<p>
The directive specifies the directory under which should be served for the corresponding path.
</p>

<div class="example">
<div class="caption">Example. Serving files under different paths</div>
<pre><code>paths:
    &quot;/&quot;:
        file.dir: /path/to/doc-root
    &quot;/icons&quot;:
        file.dir: /path/to/icons-dir
</code></pre>
</div>


</dd>
<dt><a href="configure/syntax_and_structure.html#config_levels">Level</a>:</dt>
<dd>path</dd>
<dt>See also:</dt>
<dd><a href="configure/file_directives.html#file.dirlisting"><code>file.dirlisting</code></a>,
<a href="configure/file_directives.html#file.file"><code>file.file</code></a>,
<a href="configure/file_directives.html#file.index"><code>file.index</code></a>
</dd>
</dl>

<div id="file.dirlisting" class="directive-head">
<h3><a href="configure/file_directives.html#file.dirlisting"><code>"file.dirlisting"</code></a></h3>
</div>

<dl class="directive-desc">
<dt>Description:</dt>
<dd>
<p>
A boolean flag (<code>OFF</code>, or <code>ON</code>) specifying whether or not to send the directory listing in case none of the index files exist.

</p>

</dd>
<dt><a href="configure/syntax_and_structure.html#config_levels">Level</a>:</dt>
<dd>global, host, path</dd>
<dt>Default:</dt>
<dd><code><pre>file.dirlisting: OFF</pre></code>
<dt>See also:</dt>
<dd><a href="configure/file_directives.html#file.dir"><code>file.dir</code></a>
</dd>
</dl>
<div id="file.etag" class="directive-head">
<h3><a href="configure/file_directives.html#file.etag"><code>"file.etag"</code></a></h3>
</div>

<dl class="directive-desc">
<dt>Description:</dt>
<dd>
<p>
A boolean flag (<code>OFF</code>, or <code>ON</code>) specifying whether or not to send etags.

</p>

</dd>
<dt><a href="configure/syntax_and_structure.html#config_levels">Level</a>:</dt>
<dd>global, host, path</dd>
<dt>Default:</dt>
<dd><code><pre>file.etag: ON</pre></code>
</dl>


<div id="file.file" class="directive-head">
<div class="directive-since">since v2.0</div>
<h3><a href="configure/file_directives.html#file.file"><code>"file.file"</code></a></h3>
</div>

<dl class="directive-desc">
<dt>Description:</dt>
<dd>
<p>
The directive maps a path to a specific file.
</p>

<div class="example">
<div class="caption">Example. Mapping a path to a specific file</div>
<pre><code>paths:
  /robots.txt:
    file.file: /path/to/robots.txt
</code></pre>
</div>


</dd>
<dt><a href="configure/syntax_and_structure.html#config_levels">Level</a>:</dt>
<dd>path</dd>
<dt>See also:</dt>
<dd><a href="configure/file_directives.html#file.dir"><code>file.dir</code></a>
</dd>
</dl>

<div id="file.index" class="directive-head">
<h3><a href="configure/file_directives.html#file.index"><code>"file.index"</code></a></h3>
</div>

<dl class="directive-desc">
<dt>Description:</dt>
<dd>
<p>
Specifies the names of the files that should be served when the client sends a request against the directory.
</p>

<p>
The sequence of filenames are searched from left to right, and the first file that existed is sent to the client.
</p>

</dd>
<dt><a href="configure/syntax_and_structure.html#config_levels">Level</a>:</dt>
<dd>global, host, path</dd>
<dt>Default:</dt>
<dd><code><pre>file.index: [ &#39;index.html&#39;, &#39;index.htm&#39;, &#39;index.txt&#39; ]</pre></code>
<dt>See also:</dt>
<dd><a href="configure/file_directives.html#file.dir"><code>file.dir</code></a>
</dd>
</dl>

<div id="file.mime.addtypes" class="directive-head">
<h3><a href="configure/file_directives.html#file.mime.addtypes"><code>"file.mime.addtypes"</code></a></h3>
</div>

<dl class="directive-desc">
<dt>Description:</dt>
<dd>
<p>
The directive modifies the MIME mappings by adding the specified MIME type mappings.
</p>

<div class="example">
<div class="caption">Example. Adding MIME mappings</div>
<pre><code>file.mime.addtypes:
    &quot;application/javascript&quot;: &quot;.js&quot;
    &quot;image/jpeg&quot;: [ &quot;.jpg&quot;, &quot;.jpeg&quot; ]
</code></pre>
</div>

<p>
The default mappings is hard-coded in <a href="https://github.com/h2o/h2o/blob/master/lib/handler/mimemap/defaults.c.h">lib/handler/mimemap/defaults.c.h</a>.
</p>
<p>
It is also possible to set certain attributes for a MIME type.
The example below maps <code>.css</code> files to <code>text/css</code> type, setting <code>is_compressible</code> flag to <code>ON</code> and <code>priority</code> to highest.
</p>

<div class="example">
<div class="caption">Example. Setting MIME attributes</div>
<pre><code>file.mime.settypes:
    &quot;text/css&quot;:
         extensions: [&quot;.css&quot;]
         is_compressible: yes
         priority: highest
</code></pre>
</div>


<p>
Following attributes are recognized.
</p>

<table>
<tr><th>Attribute<th>Possible Values<th>Description
<tr><td><code>is_compressible</code><td><code>ON</code>, <code>OFF</code><td>if content is compressible
<tr><td><code>priority</code><td><code>highest<code>, <code>normal</code><td>send priority of the content
</table>

<p>
The <code>priority</code> attribute affects how the HTTP/2 protocol implementation handles the request.
For detail, please refer to the HTTP/2 directives listed in the <i>see also</i> section below.
By default, mime-types for CSS and JavaScript files are the only ones that are given <code>highest</code> priority.
</p>


</dd>
<dt><a href="configure/syntax_and_structure.html#config_levels">Level</a>:</dt>
<dd>global, host, path</dd>
<dt>See also:</dt>
<dd><a href="configure/compress_directives.html#compress"><code>compress</code></a>,
<a href="configure/http2_directives.html#http2-casper"><code>http2-casper</code></a>,
<a href="configure/http2_directives.html#http2-reprioritize-blocking-assets"><code>http2-reprioritize-blocking-assets</code></a>
</dd>
</dl>

<div id="file.mime.removetypes" class="directive-head">
<h3><a href="configure/file_directives.html#file.mime.removetypes"><code>"file.mime.removetypes"</code></a></h3>
</div>

<dl class="directive-desc">
<dt>Description:</dt>
<dd>
<p>
Removes the MIME mappings for specified extensions supplied as a sequence of extensions.
</p>

<div class="example">
<div class="caption">Example. Removing MIME mappings</div>
<pre><code>file.mime.removetypes: [ &quot;.jpg&quot;, &quot;.jpeg&quot; ]
</code></pre>
</div>


</dd>
<dt><a href="configure/syntax_and_structure.html#config_levels">Level</a>:</dt>
<dd>global, host, path</dd>
</dl>

<div id="file.mime.setdefaulttype" class="directive-head">
<h3><a href="configure/file_directives.html#file.mime.setdefaulttype"><code>"file.mime.setdefaulttype"</code></a></h3>
</div>

<dl class="directive-desc">
<dt>Description:</dt>
<dd>
<p>
Sets the default MIME-type that is used when an extension does not exist in the MIME mappings
</p>

</dd>
<dt><a href="configure/syntax_and_structure.html#config_levels">Level</a>:</dt>
<dd>global, host, path</dd>
<dt>Default:</dt>
<dd><code><pre>file.mime.setdefaulttype: &quot;application/octet-stream&quot;</pre></code>
</dl>


<div id="file.mime.settypes" class="directive-head">
<h3><a href="configure/file_directives.html#file.mime.settypes"><code>"file.mime.settypes"</code></a></h3>
</div>

<dl class="directive-desc">
<dt>Description:</dt>
<dd>
<p>
Resets the MIME mappings to given mapping.
</p>

<div class="example">
<div class="caption">Example. Resetting the MIME mappings to minimum</div>
<pre><code>file.mime.settypes:
    &quot;text/html&quot;:  [ &quot;.html&quot;, &quot;.htm&quot; ]
    &quot;text/plain&quot;: &quot;.txt&quot;
</code></pre>
</div>


</dd>
<dt><a href="configure/syntax_and_structure.html#config_levels">Level</a>:</dt>
<dd>global, host, path</dd>
</dl>

<div id="file.send-compressed" class="directive-head">
<div class="directive-since">since v2.0</div>
<h3><a href="configure/file_directives.html#file.send-compressed"><code>"file.send-compressed"</code></a></h3>
</div>

<dl class="directive-desc">
<dt>Description:</dt>
<dd>
<p>
A flag indicating how a pre-compressed file should be served.

</p>

<p>
If set to <code>ON</code>, the handler looks for a file with <code>.br</code> or <code>.gz</code> appended and sends the file, if the client is capable of transparently decoding a <a href="https://datatracker.ietf.org/doc/draft-alakuijala-brotli/">brotli</a> or <a href="https://tools.ietf.org/html/rfc1952">gzip</a>-encoded response.
For example, if a client requests a file named <code>index.html</code> with <code>Accept-Encoding: gzip</code> header and if <code>index.html.gz</code> exists, the <code>.gz</code> file is sent as a response together with a <code>Content-Encoding: gzip</code> response header.
</p>
<p>
If set to <code>OFF</code>, the handler always serves the file specified by the client.
</p>
<p>
Starting from version 2.2, <code>gunzip</code> is also supported.
If set, the handler acts identical to when the value was set to <code>ON</code>.
In addition, the handler will send an uncompressed response by dynamically decompressing the <code>.gz</code> file if the client and the server failed to agree on using a pre-compressed file as the response and if a non-compressed file was not found.
The option is useful when conserving disk space is important; it is possible to remove the uncompressed files in place for gzipped ones.
</p>

</dd>
<dt><a href="configure/syntax_and_structure.html#config_levels">Level</a>:</dt>
<dd>global, host, path</dd>
<dt>Default:</dt>
<dd><code><pre>file.send-compressed: OFF</pre></code>
<dt>See also:</dt>
<dd><a href="configure/compress_directives.html#compress"><code>compress</code></a>
</dd>
</dl>

<div id="file.send-gzip" class="directive-head">
<h3><a href="configure/file_directives.html#file.send-gzip"><code>"file.send-gzip"</code></a></h3>
</div>

<dl class="directive-desc">
<dt>Description:</dt>
<dd>
<p>
Obsoleted in 2.0.
Synonym of <a href="configure/file_directives.html#file.send-compressed"><code>file.send-compressed</code></a>.

</p>

</dd>
<dt><a href="configure/syntax_and_structure.html#config_levels">Level</a>:</dt>
<dd>global, host, path</dd>
</dl>





</div>
<div id="footer">
<p>
Copyright &copy; 2015 <a href="http://dena.com/intl/">DeNA Co., Ltd.</a> et al.
</p>
</div>
</body>
</html>