summaryrefslogtreecommitdiffhomepage
path: root/docs/xml/http/ngx_http_core_module.xml
blob: 3412e49f7bc1c074fd3d1b04022d4527450aaba3 (plain) (blame)
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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
<?xml version="1.0"?>

<!DOCTYPE module SYSTEM "../../dtd/module.dtd">

<module name="HTTP Core Module" id="http_core_module">

<section id="directives" name="Directives">

<directive name="aio" appeared-in="0.8.11">
<syntax>aio
        <value>on</value> |
        <value>off</value> |
        <value>sendfile</value>
</syntax>
<default>aio off</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Enables or disables the use of asynchronous file I/O (AIO)
on FreeBSD and Linux.
</para>

<para>
On FreeBSD, AIO is usable starting from FreeBSD&nbsp;4.3.
AIO can either be linked statically into a kernel:
<example>
options VFS_AIO
</example>
or loaded dynamically as a kernel loadable module:
<example>
kldload aio
</example>
</para>

<para>
In FreeBSD versions 5 and 6, enabling AIO statically, or dynamically
when booting the kernel, will cause the entire networking subsystem
to use the Giant lock that can impact overall performance negatively.
This limitation has been removed in FreeBSD&nbsp;6.4-STABLE in 2009, and in
FreeBSD&nbsp;7.
However, starting from FreeBSD&nbsp;5.3 it is possible to enable AIO
without the penalty of running the networking subsystem under a
Giant lock&mdash;for this to work, the AIO module needs to be loaded
after the kernel has booted.
In this case, the following message will appear in
<pathname>/var/log/messages</pathname>
<example>
WARNING: Network stack Giant-free, but aio requires Giant.
Consider adding 'options NET_WITH_GIANT' or setting debug.mpsafenet=0
</example>
and can safely be ignored.
<note>
The requirement to use the Giant lock with AIO is related to the
fact that FreeBSD supports asynchronous calls
<c-func>aio_read</c-func>
and
<c-func>aio_write</c-func>
when working with sockets.
However, since nginx only uses AIO for disk I/O, no problems should arise.
</note>
</para>

<para>
For AIO to work,
<link id="sendfile">sendfile</link>
needs to be disabled:
<example>
location /video/ {
    sendfile       off;
    aio            on;
    output_buffers 1 64k;
}
</example>
</para>

<para>
In addition, starting from FreeBSD&nbsp;5.2.1 and nginx&nbsp;0.8.12, AIO can
also be used to pre-load data for <c-func>sendfile</c-func>:
<example>
location /video/ {
    sendfile       on;
    tcp_nopush     on;
    aio            sendfile;
}
</example>
In this configuration, <c-func>sendfile</c-func> is called with
the <c-def>SF_NODISKIO</c-def> flag which causes it not to
block on disk I/O and instead report back when the data are not in
memory; nginx then initiates an asynchronous data load by reading
one byte. The FreeBSD kernel then loads the first 128K bytes
of a file into memory, however next reads will only load data
in 16K chunks. This can be tuned using the
<link id="read_ahead">read_ahead</link>
directive.
</para>

<para>
On Linux, AIO is usable starting from kernel version 2.6.22;
plus, it is also necessary to enable
<link id="directio">directio</link>,
otherwise reading will be blocking:
<example>
location /video/ {
    aio            on;
    directio       512;
    output_buffers 1 128k;
}
</example>
</para>

<para>
On Linux,
<link id="directio">directio</link>
can only be used for reading blocks that are aligned on 512-byte
boundaries (or 4K for XFS).
Reading of unaligned file's end is still made in blocking mode.
The same holds true for byte range requests, and for FLV requests
not from the beginning of a file: reading of unaligned data at the
beginning and end of a file will be blocking.
There is no need to turn off
<link id="sendfile">sendfile</link>
explicitly as it is turned off automatically when
<link id="directio">directio</link>
is used.
</para>

</directive>


<directive name="alias">
<syntax>alias <argument>path</argument></syntax>
<default/>
<context>location</context>

<para>
Defines a replacement for the specified location.
For example, with the following configuration
<example>
location /i/ {
    alias /data/w3/images/;
}
</example>
the request of
<dq><code>/i/top.gif</code></dq> will be responded
with the file
<dq><pathname>/data/w3/images/top.gif</pathname></dq>.
</para>

<para>
The <argument>path</argument> value can contain variables.
</para>

<para>
If <command>alias</command> is used inside a location defined
with a regular expression then such regular expression should
contain captures and <command>alias</command> should refer to
these captures (0.7.40), for example:
<example>
location ~ ^/users/(.+\.(?:gif|jpe?g|png))$ {
    alias /data/w3/images/$1;
}
</example>
</para>

<para>
When location matches the last part of the directive's value:
<example>
location /images/ {
    alias /data/w3/images/;
}
</example>
it is better to use the
<link id="root">root</link>
directive instead:
<example>
location /images/ {
    root /data/w3;
}
</example>
</para>

</directive>


<directive name="client_body_in_file_only">
<syntax>client_body_in_file_only
        <value>on</value> |
        <value>clean</value> |
        <value>off</value>
</syntax>
<default>client_body_in_file_only off</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Determines whether nginx should save the entire client request body
into a file.
This directive can be used during debugging, or when using the
<var>$request_body_file</var>
variable, or the
<link doc="ngx_http_perl_module.xml" id="methods">$r->request_body_file</link>
method of the
<link doc="ngx_http_perl_module.xml">http_perl</link> module.
</para>

<para>
When set to the value <value>on</value>, temporary files are not
removed after request processing.
</para>

<para>
The value <value>clean</value> will cause the temporary files
left after request processing to be removed.
</para>

</directive>


<directive name="client_body_in_single_buffer">
<syntax>client_body_in_single_buffer <value>on</value> | <value>off</value>
</syntax>
<default>client_body_in_single_buffer off</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Determines whether nginx should save the entire client request body
in a single buffer.
The directive is recommended when using the
<var>$request_body</var>
variable, to save the number of copy operations involved.
</para>

</directive>


<directive name="client_body_buffer_size">

<syntax>client_body_buffer_size <argument>size</argument></syntax>
<default>client_body_buffer_size 8k/16k</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Sets buffer size for reading client request body.
In case request body is larger than the buffer,
the whole body or only its part is written to a temporary file.
<!-- ссылку на соотв. директивы про временные файлы? -->
By default, buffer size is equal to two memory pages.
This is 8K on x86, other 32-bit platforms, and x86-64.
It is usually 16K on other 64-bit platforms.
</para>

</directive>


<directive name="client_body_temp_path">
<syntax>client_body_temp_path
        <argument>path</argument>
        [<argument>level1</argument>
        [<argument>level2</argument>
        [<argument>level3</argument>]]]
</syntax>
<default>client_body_temp_path client_body_temp</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Defines a directory for storing temporary files holding client request bodies.
Up to three-level subdirectory hierarchy can be used underneath the specified
directory.
For example, in the following configuration
<example>
client_body_temp_path /spool/nginx/client_temp 1 2;
</example>
a temporary file might look like this:
<example>
/spool/nginx/client_temp/7/45/00000123457
</example>
</para>

</directive>


<directive name="client_body_timeout">
<syntax>client_body_timeout <argument>time</argument></syntax>
<default>client_body_timeout 60</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Defines a timeout for reading client request body.
A timeout is only set between two successive read operations,
not for the transmission of the whole request body.
If a client does not transmit anything within this time,
the error
<http-error code="408" text="Request time out"/>
is returned.
</para>

</directive>


<directive name="client_header_buffer_size">
<syntax>client_header_buffer_size <argument>size</argument></syntax>
<default>client_header_buffer_size 1k</default>
<context>http</context>
<context>server</context>

<para>
Sets buffer size for reading client request header.
For most requests, a buffer of 1K bytes is enough.
However, if a request includes long cookies, or comes from a WAP client,
it may not fit into 1K.
If a request line, or a request header field do not fit entirely into
this buffer then larger buffers are allocated, configured by the
<link id="large_client_header_buffers">large_client_header_buffers</link>
directive.
</para>

</directive>


<directive name="client_header_timeout">
<syntax>client_header_timeout <argument>time</argument></syntax>
<default>client_header_timeout 60</default>
<context>http</context>
<context>server</context>

<para>
Defines a timeout for reading client request header.
If a client does not transmit the entire header within this time,
the error
<http-error code="408" text="Request time out"/>
is returned.
</para>

</directive>


<directive name="client_max_body_size">
<syntax>client_max_body_size <argument>size</argument></syntax>
<default>client_max_body_size 1m</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Sets the maximum allowed size of the client request body,
specified in the
<header>Content-Length</header>
request header field.
If <argument>size</argument> is greater than the configured value, the
<http-error code="413" text="Request Entity Too Large"/>
error is returned to a client.
Please be aware that
<link doc="/web/upload.xml">browsers cannot correctly display
this error</link>.
</para>

</directive>


<directive name="default_type">
<syntax>default_type <argument>mime-type</argument></syntax>
<default>default_type text/plain</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Defines a default MIME-type of a response.
</para>

</directive>


<directive name="directio" appeared-in="0.7.7">
<syntax>directio <argument>size</argument> | <value>off</value></syntax>
<default>directio off</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Enables the use of
the <c-def>O_DIRECT</c-def> flag (FreeBSD, Linux),
the <c-def>F_NOCACHE</c-def> flag (Mac OS X),
or the <c-func>directio</c-func> function (Solaris),
when reading files that are larger than the specified <argument>size</argument>.
It automatically disables (0.7.15) the use of
<link id="sendfile">sendfile</link>
for a given request.
It could be useful for serving large files:
<example>
directio 4m;
</example>
or when using <link id="aio">aio</link> on Linux.
</para>

</directive>


<directive name="directio_alignment" appeared-in="0.8.11">
<syntax>directio_alignment <argument>size</argument></syntax>
<default>directio_alignment 512</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Sets an alignment for
<link id="directio">directio</link>.
In most cases, a 512-byte alignment is enough, however, when
using XFS under Linux, it needs to be increased to 4K.
</para>

</directive>


<directive name="error_page">
<syntax>error_page
        <argument>code</argument> ...
        [<value>=</value>[<argument>response</argument>]]
        <argument>uri</argument>
</syntax>
<default/>
<context>http</context>
<context>server</context>
<context>location</context>
<context>if in location</context>

<para>
Defines the URI that will be shown for the specified errors.
These directives are inherited from the previous level if and
only if there are no
<command>error_page</command>
directives on
the current level.
A URI value can contain variables.
</para>

<para>
Example:
<example>
error_page 404         /404.html;
error_page 502 503 504 /50x.html;
error_page 403         http://example.com/forbidden.html;
</example>
</para>

<para>
Furthermore, it is possible to change the response code to another, for example:
<example>
error_page 404 =200 /empty.gif;
</example>
</para>

<para>
If an error response is processed by a proxied server, or a FastCGI server,
and the server may return different response codes (e.g., 200, 302, 401
or 404), it is possible to respond with a returned code:
<example>
error_page 404 = /404.php;
</example>
</para>

<para>
If there is no need to change URI during redirection it is possible to redirect
error processing into a named location:
<example>
location / {
    error_page 404 = @fallback;
}

location @fallback {
    proxy_pass http://backend;
}
</example>
</para>

</directive>


<directive name="if_modified_since" appeared-in="0.7.24">
<syntax>if_modified_since
        <value>off</value> |
        <value>exact</value> |
        <value>before</value>
</syntax>
<default>if_modified_since exact</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Specifies how to compare modification time of a response
with the time in the
<header>If-Modified-Since</header>
request header:

<list type="tag">

<tag-name><value>off</value></tag-name>
<tag-desc>
the
<header>If-Modified-Since</header> request header is ignored (0.7.34);
</tag-desc>

<tag-name><value>exact</value></tag-name>
<tag-desc>
exact match;
</tag-desc>

<tag-name><value>before</value></tag-name>
<tag-desc>
modification time of a response is
less than or equal to the time in the <header>If-Modified-Since</header>
request header.
</tag-desc>

</list>
</para>

</directive>


<directive name="internal">
<syntax>internal</syntax>
<default/>
<context>location</context>

<para>
Specifies that a given location can only be used for internal requests.
For external requests, the <http-error code="404" text="Not found"/>
error is returned.
Internal requests are the following:

<list type="bullet">

<listitem>
requests redirected by the <link id="error_page">error_page</link> directive;
</listitem>

<listitem>
subrequests formed by the
<command>include virtual</command>
command of the
<link doc="ngx_http_ssi_module.xml">http_ssi</link> module;
</listitem>

<listitem>
requests changed by the
<link doc="ngx_http_rewrite_module.xml" id="rewrite">rewrite</link>
directive of the
<link doc="ngx_http_rewrite_module.xml">http_rewrite</link> module.
</listitem>

</list>
</para>

<para>
Example:
<example>
error_page 404 /404.html;

location /404.html {
    internal;
}
</example>
</para>

</directive>


<directive name="keepalive_requests" appeared-in="0.8.0">
<syntax>keepalive_requests <argument>number</argument></syntax>
<default>keepalive_requests 100</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Sets the maximum number of requests that can be
made through one keep-alive connection.
</para>

</directive>


<directive name="keepalive_timeout">
<syntax>keepalive_timeout
        <argument>time</argument>
        [<argument>time</argument>]
</syntax>
<default>keepalive_timeout 75</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
The first argument sets a timeout during which a keep-alive
client connection will stay open on the server side.
The optional second argument sets a value in the
<dq><header>Keep-Alive: timeout=<argument>time</argument></header></dq>
response header.
Two arguments may differ.
</para>

<para>
The
<dq><header>Keep-Alive: timeout=</header></dq>
is understood by Mozilla and Konqueror.
MSIE will close keep-alive connection in about 60 seconds.
</para>

</directive>


<directive name="large_client_header_buffers">
<syntax>large_client_header_buffers <argument>number size</argument></syntax>
<default>large_client_header_buffers 4 4k/8k</default>
<context>http</context>
<context>server</context>

<para>
Sets the maximum <argument>number</argument> and <argument>size</argument> of
buffers used when reading large client request headers.
A request line cannot exceed the size of one buffer, or the
<http-error code="414" text="Request URI too large"/>
error is returned.
A request header field cannot exceed the size of one buffer as well, or the
<http-error code="400" text="Bad request"/>
error is returned.
Buffers are allocated only on demand.
By default, the buffer size is equal to one memory page size.
It is either 4K or 8K, platform dependent.
If after the end of request processing a connection is transitioned
into the keep-alive state, these buffers are freed.
</para>

</directive>


<directive name="limit_except">
<syntax>limit_except <argument>method</argument> ... { ... }</syntax>
<default/>
<context>location</context>

<para>
Limits allowed HTTP methods inside a location.
The GET method also implies the HEAD method.
Access to other methods can be limited using the
<link doc="ngx_http_access_module.xml">http_access</link>
and
<link doc="ngx_http_auth_basic_module.xml">http_auth_basic</link>
modules directives:
<example>
limit_except GET {
    allow 192.168.1.0/32;
    deny  all;
}
</example>
Please note that this will limit access to all methods
<emphasis>except</emphasis> GET and HEAD.
</para>

</directive>


<directive name="limit_rate">
<syntax>limit_rate <argument>rate</argument></syntax>
<default/>
<context>http</context>
<context>server</context>
<context>location</context>
<context>if in location</context>

<para>
Rate limits the transmission of a response to a client.
The <argument>rate</argument> is specified in bytes per second.
<!--
The smaller the rate, the more accurate will be the limitation.
-->
The limit is per connection, so if a single client opens 2 connections,
an overall rate will be 2x more than specified.
</para>

<para>
This directive is not applicable if one wants to rate limit
a group of clients on the
<link id="server">server</link>
level.
If that is the case, the desired limit can be specified in the
<var>$limit_rate</var>
variable:
<example>
server {

    if ($slow) {
        set $limit_rate 4k;
    }

    ...
}
</example>
</para>

</directive>


<directive name="limit_rate_after" appeared-in="0.8.0">
<syntax>limit_rate_after <argument>size</argument></syntax>
<default/>
<context>http</context>
<context>server</context>
<context>location</context>
<context>if in location</context>

<para>
Sets the initial amount after which the further transmission
of a response to a client will be rate limited.
</para>

<para>
Example:
<example>
location /flv/ {
    flv;
    limit_rate_after 500k;
    limit_rate       50k;
}
</example>
</para>

</directive>


<directive name="listen">
<syntax>listen
        <argument>address</argument>[:<argument>port</argument>]
        [<parameter>default</parameter> | <parameter>default_server</parameter>
        [<parameter>backlog</parameter>=<argument>number</argument>]
        [<parameter>rcvbuf</parameter>=<argument>size</argument>]
        [<parameter>sndbuf</parameter>=<argument>size</argument>]
        [<parameter>accept_filter</parameter>=<argument>filter</argument>]
        [<parameter>deferred</parameter>]
        [<parameter>bind</parameter>]
        [<parameter>ipv6only</parameter>=<value>on</value>|<value>off</value>]
        [<parameter>ssl</parameter>]]
</syntax>
<syntax>listen
        <argument>port</argument>
        [<parameter>default</parameter> | <parameter>default_server</parameter>
        [<parameter>backlog</parameter>=<argument>number</argument>]
        [<parameter>rcvbuf</parameter>=<argument>size</argument>]
        [<parameter>sndbuf</parameter>=<argument>size</argument>]
        [<parameter>accept_filter</parameter>=<argument>filter</argument>]
        [<parameter>deferred</parameter>]
        [<parameter>bind</parameter>]
        [<parameter>ipv6only</parameter>=<value>on</value>|<value>off</value>]
        [<parameter>ssl</parameter>]]
</syntax>
<default>listen *:80 | *:8000</default>
<context>server</context>

<para>
Sets an <argument>address</argument> and a <argument>port</argument>, on which
the server will accept requests.
Only one of <argument>address</argument> or <argument>port</argument> can be
specified.
An <argument>address</argument> may also be a hostname, for example:
<example>
listen 127.0.0.1:8000;
listen 127.0.0.1;
listen 8000;
listen *:8000;
listen localhost:8000;
</example>
IPv6 addresses (0.7.36) are specified in square brackets:
<example>
listen [::]:8000;
listen [fe80::1];
</example>
</para>

<para>
If only <argument>address</argument> is given, the port 80 is used.
</para>

<para>
If directive is not present then either the <code>*:80</code> is used
if nginx runs with superuser privileges, or <code>*:8000</code> otherwise.
</para>

<para>
The <parameter>default</parameter> parameter, if present,
will cause the server to become the default server for the specified
<argument>address</argument>:<argument>port</argument> pair.
If none of the directives have the <parameter>default</parameter>
parameter then the first server with the
<argument>address</argument>:<argument>port</argument> pair will be
the default server for this pair.
Starting from version 0.8.21 it is possible to use the
<parameter>default_server</parameter>
parameter.
</para>

<para>
A <code>listen</code> directive which has the <parameter>default</parameter>
parameter can have several additional parameters specific to system calls
<c-func>listen</c-func> and <c-func>bind</c-func>.
Starting from version 0.8.21, these parameters can be specified in any
<code>listen</code> directive, but only once for the given
<argument>address</argument>:<argument>port</argument> pair.
<list type="tag">

<tag-name>
<parameter>backlog</parameter>=<argument>number</argument>
</tag-name>
<tag-desc>
sets the <parameter>backlog</parameter> parameter in the
<c-func>listen</c-func> call.
By default, <parameter>backlog</parameter> equals -1 on FreeBSD
and 511 on other platforms.
</tag-desc>

<tag-name>
<parameter>rcvbuf</parameter>=<argument>size</argument>
</tag-name>
<tag-desc>
sets the <c-def>SO_RCVBUF</c-def> parameter for the listening socket.
</tag-desc>

<tag-name>
<parameter>sndbuf</parameter>=<argument>size</argument>
</tag-name>
<tag-desc>
sets the <c-def>SO_SNDBUF</c-def> parameter for the listening socket.
</tag-desc>

<tag-name>
<parameter>accept_filter</parameter>=<argument>filter</argument>
</tag-name>
<tag-desc>
sets the name of the accept filter.
This works only on FreeBSD, acceptable values are <value>dataready</value>
and <value>httpready</value>.
On receipt of the <c-def>SIGHUP</c-def> signal, an accept filter can only be
changed in recent versions of FreeBSD, starting from 6.0, 5.4-STABLE
and 4.11-STABLE.
</tag-desc>

<tag-name>
<parameter>deferred</parameter>
</tag-name>
<tag-desc>
instructs to use a deferred <c-func>accept</c-func> on Linux
using the <c-def>TCP_DEFER_ACCEPT</c-def> option.
</tag-desc>

<tag-name>
<parameter>bind</parameter>
</tag-name>
<tag-desc>
specifies to make a separate <c-func>bind</c-func> call for a given
<argument>address</argument>:<argument>port</argument> pair.
This is because nginx will only <c-func>bind</c-func> to
<code>*</code>:<argument>port</argument>
if there are several <code>listen</code> directives with
the same port but different addresses, and one of the
<code>listen</code> directives listens on all addresses
for the given port (<code>*</code>:<argument>port</argument>).
It should be noted that in this case a <c-func>getsockname</c-func>
system call will be made to determine an address that accepted a
connection.
If parameters <parameter>backlog</parameter>, <parameter>rcvbuf</parameter>,
<parameter>sndbuf</parameter>, <parameter>accept_filter</parameter>, or
<parameter>deferred</parameter> are used then for a given
<argument>address</argument>:<argument>port</argument> pair
a separate <c-func>bind</c-func> call will always be made.
</tag-desc>

<tag-name>
<parameter>ipv6only</parameter>=<value>on</value>|<value>off</value>
</tag-name>
<tag-desc>
this parameter (0.7.42) sets the value of the <c-def>IPV6_V6ONLY</c-def>
parameter for the listening socket.
This parameter can only be set once on start.
</tag-desc>

<tag-name>
<parameter>ssl</parameter>
</tag-name>
<tag-desc>
this parameter (0.7.14) does not relate to system calls
<c-func>listen</c-func> and <c-func>bind</c-func>, but allows to
specify that all connections accepted on this port should work in
the SSL mode.
This allows for a more compact configuration for the server operating
in both HTTP and HTTPS modes simultaneously.
<example>
listen 80;
listen 443 default ssl;
</example>
</tag-desc>

</list>
</para>

<para>
Example:
<example>
listen 127.0.0.1 default accept_filter=dataready backlog=1024;
</example>
</para>

</directive>


<directive name="location">
<syntax>location [
        <value>=</value> |
	<value>~</value> |
	<value>~*</value> |
	<value>^~</value> |
	<value>@</value>
	] <argument>uri</argument>
{ ... }</syntax>
<default/>
<context>server</context>
<!--
<context>location</context>
-->

<para>
Sets a configuration based on a request URI.
A location can either be defined by a prefix string, or by a regular expression.
Regular expressions are specified by prepending them with the
<dq><value>~*</value></dq> prefix (for case-insensitive matching), or with the
<dq><value>~</value></dq> prefix (for case-sensitive matching).
To find a location matching a given request, nginx first checks
locations defined using the prefix strings (prefix locations).
Amongst them, the most specific one is searched.
Then regular expressions are checked, in the order of their appearance
in a configuration file.
A search terminates on the first match, and its corresponding
configuration is used.
If no match with a regular expression location is found then a
configuration of the most specific prefix location is used.
</para>

<para>
For case-insensitive operating systems such as Mac OS X and Cygwin,
the string matching ignores a case (0.7.7).
However, comparison is limited to one-byte locales.
</para>

<para>
Regular expressions can contain captures (0.7.40) that can later
be used in other directives.
</para>

<para>
If the most specific prefix location has the <dq><value>^~</value></dq> prefix
then regular expressions are not checked.
</para>

<para>
Also, using the <dq><value>=</value></dq> prefix it is possible to define
an exact match of URI and location.
If an exact match is found, the search terminates.
For example, if a <dq><code>/</code></dq> request happens frequently,
defining <dq><code>location = /</code></dq> will speed up the processing
of these requests, as search terminates right after the first
comparison.
</para>

<para>
In versions from 0.7.1 to 0.8.41, if a request matched the prefix
location without the <dq><value>=</value></dq> and <dq><value>^~</value></dq>
prefixes, the search also terminated and regular expressions were
not checked.
</para>

<para>
Let's illustrate the above by example:
<example>
location = / {
    [ configuration A ]
}

location / {
    [ configuration B ]
}

location ^~ /images/ {
    [ configuration C ]
}

location ~* \.(gif|jpg|jpeg)$ {
    [ configuration D ]
}
</example>
The <dq><code>/</code></dq> request will match configuration A,
the <dq><code>/documents/document.html</code></dq> request will match
configuration B,
the <dq><code>/images/1.gif</code></dq> request will match configuration C, and
the <dq><code>/documents/1.jpg</code></dq> request will match configuration D.
</para>

<para>
The <dq><value>@</value></dq> prefix defines a named location.
Such a location is not used for a regular request processing, but instead
used for request redirection.
</para>

<!--
<migration from="Apache" directive="Location" />
-->

</directive>


<directive name="log_not_found">
<syntax>log_not_found <value>on</value> | <value>off</value></syntax>
<default>log_not_found on</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Enables or disables logging of errors about not found files into the
<link doc="../ngx_core_module.xml" id="error_log">error_log</link>.
</para>

</directive>


<directive name="log_subrequest">
<syntax>log_subrequest <value>on</value> | <value>off</value></syntax>
<default>log_subrequest off</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Enables or disables logging of subrequests into the
<link doc="ngx_http_log_module.xml" id="access_log">access_log</link>.
</para>

</directive>


<directive name="merge_slashes">
<syntax>merge_slashes <value>on</value> | <value>off</value></syntax>
<default>merge_slashes on</default>
<context>http</context>
<context>server</context>

<para>
Enables or disables compression of two or more adjacent slashes
in a URI into a single slash.
</para>

<para>
Note that compression is essential for the correct prefix string
and regular expressions location matching.
Without it, the <dq><code>//scripts/one.php</code></dq> request would not match
<example>
location /scripts/ {
    ...
}
</example>
and might be processed as a static file,
so it gets converted to <dq><code>/scripts/one.php</code></dq>.
</para>

<para>
Turning the compression <value>off</value> can become necessary if a URI
contains base64-encoded names, since base64 uses the "/" character internally.
However, for security considerations, it is better to avoid turning off
the compression.
</para>

<para>
If a directive is specified on the
<link id="server">server</link>
level, which is also a default server, its value will cover
all virtual servers listening on the same address and port.
</para>

</directive>


<directive name="msie_padding">
<syntax>msie_padding <value>on</value> | <value>off</value></syntax>
<default>msie_padding on</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Enables or disables adding of comments to responses with status
greater than 400 for MSIE clients, to pad the response size to 512 bytes.
</para>

</directive>


<directive name="msie_refresh">
<syntax>msie_refresh <value>on</value> | <value>off</value></syntax>
<default>msie_refresh off</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Enables or disables issuing refreshes instead of redirects, for MSIE clients.
</para>

</directive>


<directive name="open_file_cache">
<syntax>open_file_cache
<parameter>max</parameter>=<argument>N</argument>
[<parameter>inactive</parameter>=<argument>time</argument>] |
<value>off</value>
</syntax>
<default>open_file_cache off</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Configures a cache that can store:
<list type="bullet">

<listitem>
open file descriptors, their sizes and modification times;
</listitem>

<listitem>
directory lookups;
</listitem>

<listitem>
file lookup errors, such as "file not found", "no read permission",
and so on.
Caching of errors should be enabled separately by the
<link id="open_file_cache_errors">open_file_cache_errors</link>
directive.
</listitem>

</list>
</para>

<para>
The directive has the following parameters:
<list type="tag">

<tag-name>
<parameter>max</parameter>
</tag-name>
<tag-desc>
sets the maximum number of elements in the cache;
on cache overflow the least recently used (LRU) elements get removed;
</tag-desc>

<tag-name>
<parameter>inactive</parameter>
</tag-name>
<tag-desc>
defines a time, after which the element gets removed from the cache
if there were no accesses to it during this time;
by default, it is 60 seconds;
</tag-desc>

<tag-name>
<value>off</value>
</tag-name>
<tag-desc>
disables the cache.
</tag-desc>

</list>
</para>

<para>
Example:
<example>
open_file_cache          max=1000 inactive=20s;
open_file_cache_valid    30s;
open_file_cache_min_uses 2;
open_file_cache_errors   on;
<!--
open_file_cache_events   on;
-->
</example>
</para>

</directive>


<directive name="open_file_cache_errors">
<syntax>open_file_cache_errors <value>on</value> | <value>off</value></syntax>
<default>open_file_cache_errors off</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Enables or disables caching of file lookup errors by the
<link id="open_file_cache">open_file_cache</link>.
</para>

</directive>


<!--

<directive name="open_file_cache_events">
<syntax>open_file_cache_events <value>on</value> | <value>off</value></syntax>
<default>open_file_cache_events off</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Enables to use kernel events to validate
<link id="open_file_cache">open_file_cache</link>
elements.
This directive works with the
<link doc="../events.xml" id="kqueue">kqueue</link>
method only.
Note that only NetBSD&nbsp;2.0+ and FreeBSD&nbsp;6.0+
support events for arbitrary file system types.
Other operating systems support events only for essential
file systems such as UFS or FFS.
</para>

</directive>

-->


<directive name="open_file_cache_min_uses">
<syntax>open_file_cache_min_uses <argument>number</argument></syntax>
<default>open_file_cache_min_uses 1</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Sets the minimum <argument>number</argument> of file accesses during
the period configured by the <parameter>inactive</parameter> parameter
of the <link id="open_file_cache">open_file_cache</link> directive,
after which a file descriptor will remain open in the cache.
</para>

</directive>


<directive name="open_file_cache_valid">
<syntax>open_file_cache_valid <argument>time</argument></syntax>
<default>open_file_cache_valid 60</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Sets a time after which
<link id="open_file_cache">open_file_cache</link>
elements should be validated.
<!--
When <link id="open_file_cache_events">
open_file_cache_events</link> is enabled, open file descriptors
are checked only once, and then updated right after they get changed.
-->
</para>

</directive>


<directive name="optimize_server_names">
<syntax>optimize_server_names <value>on</value> | <value>off</value></syntax>
<default>optimize_server_names on</default>
<context>http</context>
<context>server</context>

<para>
This directive is obsolete.
</para>

<para>
Enables or disables optimization of hostname checking in name-based
virtual servers.
In particular, the checking affects hostnames used in redirects.
If optimization is enabled, and all name-based servers listening on
the same address:port pair have identical configuration, then
names are not checked during request processing, and the first
server name is used in redirects.
In case redirects should use hostnames sent by clients,
optimization needs to be disabled.
</para>

</directive>


<directive name="port_in_redirect">
<syntax>port_in_redirect <value>on</value> | <value>off</value></syntax>
<default>port_in_redirect on</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Enables or disables specifying the port in redirects issued by nginx.
</para>

</directive>


<directive name="read_ahead">
<syntax>read_ahead <argument>size</argument></syntax>
<default>read_ahead 0</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Sets the amount of pre-reading when working with files, in the kernel.
</para>

<para>
On Linux, the
<code>posix_fadvise(0, 0, 0, POSIX_FADV_SEQUENTIAL)</code>
system call is used, so the <argument>size</argument> argument is ignored.
</para>

<para>
On FreeBSD, the
<code>fcntl(O_READAHEAD,</code><argument>size</argument><code>)</code>
system call is used, supported in FreeBSD&nbsp;9.0-CURRENT.
FreeBSD&nbsp;7 needs to be
<link url="http://sysoev.ru/freebsd/patch.readahead.txt">patched</link>.
</para>

</directive>


<directive name="recursive_error_pages">
<syntax>recursive_error_pages <value>on</value> | <value>off</value></syntax>
<default>recursive_error_pages off</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Enables or disables doing several redirects using the
<link id="error_page">error_page</link>
directive.
</para>

</directive>


<directive name="reset_timedout_connection">
<syntax>reset_timedout_connection
        <value>on</value> | <value>off</value></syntax>
<default>reset_timedout_connection off</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Enables or disables resetting of timed out connections.
The reset is performed as follows: before closing a socket, the
<c-def>SO_LINGER</c-def>
option is set on it with a timeout value of 0.
When the socket is closed, a client is sent TCP RST, and all memory
occupied by this socket is freed.
This avoids keeping of an already closed socket with filled buffers
for a long time, in a FIN_WAIT1 state.
</para>

<para>
It should be noted that timed out keep-alive connections are still
closed normally.
</para>

</directive>


<directive name="resolver">
<syntax>resolver <argument>address</argument></syntax>
<default/>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Sets the <argument>address</argument> of a name server, for example:
<example>
resolver 127.0.0.1;
</example>
</para>

</directive>


<directive name="resolver_timeout">
<syntax>resolver_timeout <argument>time</argument></syntax>
<default>resolver_timeout 30s</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Sets a timeout for name resolution, for example:
<example>
resolver_timeout 5s;
</example>
</para>

</directive>


<directive name="root">
<syntax>root <argument>path</argument></syntax>
<default>root html</default>
<context>http</context>
<context>server</context>
<context>location</context>
<context>if in location</context>

<para>
Sets the root directory for requests.
For example, with the following configuration
<example>
location /i/ {
    root /data/w3;
}
</example>
<dq><code>/i/top.gif</code></dq> will be responded
with the file
<dq><pathname>/data/w3/i/top.gif</pathname></dq>.
</para>

<para>
The <argument>path</argument> value can contain variables.
</para>

<para>
A path to the file is constructed by merely adding a URI to the value
of the <command>root</command> directive.
If a URI need to be modified, the
<link id="alias">alias</link> directive should be used.
</para>

</directive>


<directive name="satisfy">
<syntax>satisfy <value>all</value> | <value>any</value></syntax>
<default>satisfy all</default>
<context>location</context>

<para>
Allows access if any of the
<link doc="ngx_http_access_module.xml">http_access</link>
or <link doc="ngx_http_auth_basic_module.xml">http_auth_basic</link>
modules grant access.
<example>
location / {
    satisfy any;

    allow 192.168.1.0/32;
    deny  all;

    auth_basic           "closed site";
    auth_basic_user_file conf/htpasswd;
}
</example>
</para>

</directive>


<directive name="satisfy_any">
<syntax>satisfy_any <value>on</value> | <value>off</value></syntax>
<default>satisfy_any off</default>
<context>location</context>

<para>
This directive was renamed to the <link id="satisfy">satisfy</link> directive.
</para>

</directive>


<directive name="send_timeout">
<syntax>send_timeout <argument>time</argument></syntax>
<default>send_timeout 60</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Sets a timeout for transmitting a response to the client.
A timeout is only set between two successive write operations,
not for the transmission of the whole response.
If a client does not receive anything within this time,
a connection is closed.
</para>

</directive>


<directive name="sendfile">

<syntax>sendfile <value>on</value> | <value>off</value></syntax>
<default>sendfile off</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Enables or disables the use of
<c-func>sendfile</c-func>.
</para>

</directive>


<directive name="server">
<syntax>server { ... }</syntax>
<default/>
<context>http</context>

<para>
Sets a configuration for the virtual server.
There is no clean separation between IP-based (based on the IP address)
and name-based (based on the <header>Host</header> request header field)
virtual servers.
Instead, the <link id="listen">listen</link> directives describe all
addresses and ports that should accept connections for a server, and the
<link id="server_name">server_name</link> directive lists all server names.
An example configuration is provided in the
<link doc="../virtual_hosts.xml">
Setting Up Virtual Servers</link> document.
</para>

</directive>


<directive name="server_name">
<syntax>server_name <argument>name</argument> ...</syntax>
<default>server_name hostname</default>
<context>server</context>

<para>
Sets names of the virtual server, for example:
<example>
server {
    server_name example.com www.example.com;
}
</example>
</para>

<para>
The first name becomes a primary server name.
By default, the machine's hostname is used.
Server names can include an asterisk (<dq><code>*</code></dq>)
to replace the first or last part of a name:
<example>
server {
    server_name example.com *.example.com www.example.*;
}
</example>
</para>

<para>
The first two of the above mentioned names can be combined:
<example>
server {
    server_name .example.com;
}
</example>
</para>

<para>
It is also possible to use regular expressions in server names,
prepending the name with a tilde (<dq><code>~</code></dq>):
<example>
server {
    server_name www.example.com ~^www\d+\.example\.com$;
}
</example>
</para>

<para>
Regular expressions can contain captures (0.7.40) that can later
be used in other directives:
<example>
server {
    server_name ~^(www\.)?(.+)$;

    location / {
        root /sites/$2;
    }
}

server {
    server_name _;

    location / {
        root /sites/default;
    }
}
</example>
</para>

<para>
Starting from version 0.8.25, named captures in regular expressions create
variables that can later be used in other directives:
<example>
server {
    server_name ~^(www\.)?(?&lt;domain&gt;.+)$;

    location / {
        root /sites/$domain;
    }
}

server {
    server_name _;

    location / {
        root /sites/default;
    }
}
</example>
</para>

<para>
Starting from version 0.7.11, it is possible to specify an empty name:
<example>
server {
    server_name www.example.com "";
}
</example>
It allows this server to process requests without the <header>Host</header>
header, instead of the default server for the given address:port pair.
</para>

<para>
The name checking order is as follows:
<list type="enum">

<listitem>
full names
</listitem>

<listitem>
names with the prefix mask, e.g. <dq><code>*.example.com</code></dq>
</listitem>

<listitem>
names with the suffix mask, e.g. <dq><code>mail.*</code></dq>
</listitem>

<listitem>
regular expressions
</listitem>

</list>
</para>

</directive>


<directive name="server_name_in_redirect">
<syntax>server_name_in_redirect <value>on</value> | <value>off</value></syntax>
<default>server_name_in_redirect on</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Enables or disables the use of the primary server name, specified by the
<link id="server_name">server_name</link>
directive, in redirects issued by nginx.
When disabled, the name from the <header>Host</header> request header field
is used.
If this field is not present, an IP address of the server is used.
</para>

</directive>


<directive name="server_names_hash_max_size">
<syntax>server_names_hash_max_size <argument>size</argument></syntax>
<default>server_names_hash_max_size 512</default>
<context>http</context>

<para>
Sets the maximum <argument>size</argument> of the server names hash tables.
For more information, please refer to
<link doc="../hash.xml">Setting Up Hashes</link>.
</para>

</directive>


<directive name="server_names_hash_bucket_size">
<syntax>server_names_hash_bucket_size <argument>size</argument></syntax>
<default>server_names_hash_bucket_size 32/64/128</default>
<context>http</context>

<para>
Sets the bucket size for the server names hash tables.
Default value depends on the size of the processor's cache line.
For more information, please refer to
<link doc="../hash.xml">Setting Up Hashes</link>.
</para>

</directive>


<directive name="server_tokens">
<syntax>server_tokens <value>on</value> | <value>off</value></syntax>
<default>server_tokens on</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Enables or disables emitting of nginx version in error messages and in the
<header>Server</header> response header field.
</para>

</directive>


<directive name="tcp_nodelay">
<syntax>tcp_nodelay <value>on</value> | <value>off</value></syntax>
<default>tcp_nodelay on</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Enables or disables the use of the <c-def>TCP_NODELAY</c-def> option.
The option is enabled only when a connection is transitioned into the
keep-alive state.
</para>

</directive>


<directive name="tcp_nopush">
<syntax>tcp_nopush <value>on</value> | <value>off</value></syntax>
<default>tcp_nopush off</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Enables or disables the use of
the <c-def>TCP_NOPUSH</c-def> socket option on FreeBSD
or the <c-def>TCP_CORK</c-def> socket option on Linux.
Opitons are enables only when <link id="sendfile">sendfile</link> is used.
Enabling the option allows to
<list type="bullet">

<listitem>
send the response header and the beginning of a file in one packet,
on Linux and FreeBSD&nbsp;4.*;
</listitem>

<listitem>
send a file in full packets.
</listitem>

</list>
</para>

</directive>


<directive name="try_files">
<syntax>try_files
        <argument>file</argument> ...
	<argument>uri</argument>
</syntax>
<syntax>try_files
        <argument>file</argument> ...
        =<argument>code</argument>
</syntax>
<default/>
<context>location</context>

<para>
Checks the existence of files in the specified order, and uses
the first found file for request processing; the processing
is performed in this location's context.
It is possible to check the directory existence by specifying
the slash at the end of a name, e.g. <dq><code>$uri/</code></dq>.
If none of the files were found, an internal redirect to the
<argument>uri</argument> specified by the last argument is made.
As of version 0.7.51, the last argument can also be a
<argument>code</argument>:
<example>
location / {
    try_files $uri $uri/index.html $uri.html =404;
}
</example>
</para>

<para>
Example when proxying Mongrel:
<example>
location / {
    try_files /system/maintenance.html
              $uri $uri/index.html $uri.html
              @mongrel;
}

location @mongrel {
    proxy_pass http://mongrel;
}
</example>
</para>

<para>
Example for Drupal/FastCGI:
<example>
location / {
    try_files $uri $uri/ @drupal;
}

location ~ \.php$ {
    try_files $uri @drupal;

    fastcgi_pass ...;

    fastcgi_param SCRIPT_FILENAME /path/to$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME     $fastcgi_script_name;
    fastcgi_param QUERY_STRING    $args;

    ... other fastcgi_param's
}

location @drupal {
    fastcgi_pass ...;

    fastcgi_param SCRIPT_FILENAME /path/to/index.php;
    fastcgi_param SCRIPT_NAME     /index.php;
    fastcgi_param QUERY_STRING    q=$uri&amp;$args;

    ... other fastcgi_param's
}
</example>
In the following example,
<example>
location / {
    try_files $uri $uri/ @drupal;
}
</example>
the <command>try_files</command> directive is equivalent to
<example>
location / {
    error_page 404 = @drupal;
    log_not_found off;
}
</example>
And here,
<example>
location ~ \.php$ {
    try_files $uri @drupal;

    fastcgi_pass ...;

    fastcgi_param SCRIPT_FILENAME /path/to$fastcgi_script_name;

    ...
}
</example>
<command>try_files</command> checks the existence of the PHP file
before passing the request to the FastCGI server.
</para>

<para>
Example for Wordpress and Joomla:
<example>
location / {
    try_files $uri $uri/ @wordpress;
}

location ~ \.php$ {
    try_files $uri @wordpress;

    fastcgi_pass ...;

    fastcgi_param SCRIPT_FILENAME /path/to$fastcgi_script_name;
    ... other fastcgi_param's
}

location @wordpress {
    fastcgi_pass ...;

    fastcgi_param SCRIPT_FILENAME /path/to/index.php;
    ... other fastcgi_param's
}
</example>
</para>

</directive>


<directive name="types">
<syntax>types { ... }</syntax>
<default>see below</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
Maps file name extensions to MIME types of responses.
Several extensions can map to one type.
The following mappings are configured by default:
<example>
types {
    text/html  html;
    image/gif  gif;
    image/jpeg jpg;
}
</example>
</para>

<para>
A sufficiently full mapping table is distributed with nginx in the
<pathname>conf/mime.types</pathname> file.
</para>

<para>
To make a particular location emit the
<dq><code>application/octet-stream</code></dq>
MIME type for all requests, try the following:
<example>
location /download/ {
    types        { }
    default_type application/octet-stream;
}
</example>
</para>

</directive>


<directive name="underscores_in_headers">
<syntax>underscores_in_headers <value>on</value> | <value>off</value></syntax>
<default>underscores_in_headers off</default>
<context>http</context>
<context>server</context>

<para>
Enables or disables the use of underscores in client request header fields.
</para>

</directive>

</section>

<section id="variables" name="Embedded Variables">

<para>
The http_core module supports embedded variables with names matching
those of the Apache Server.
First of all, these are variables representing client request header
fields, such as, <var>$http_user_agent</var>, <var>$http_cookie</var>,
and so on.
It also supports other variables:
<list type="tag">

<tag-name><var>$args</var></tag-name>
<tag-desc>
arguments in the request line
</tag-desc>

<tag-name><var>$arg_</var><argument>name</argument></tag-name>
<tag-desc>
argument <argument>name</argument> in the request line
</tag-desc>

<tag-name><var>$binary_remote_addr</var></tag-name>
<tag-desc>
client address in a binary form, value's length is always 4 bytes
</tag-desc>

<tag-name><var>$content_length</var></tag-name>
<tag-desc>
<header>Content-Length</header> request header field
</tag-desc>

<tag-name><var>$content_type</var></tag-name>
<tag-desc>
<header>Content-Type</header> request header field
</tag-desc>

<tag-name><var>$cookie_</var><argument>name</argument></tag-name>
<tag-desc>
the <argument>name</argument> cookie
</tag-desc>

<tag-name><var>$document_root</var></tag-name>
<tag-desc>
<link id="root">root</link> directive's value for the current request
</tag-desc>

<tag-name><var>$document_uri</var></tag-name>
<tag-desc>
same as <var>$uri</var>
</tag-desc>

<tag-name><var>$host</var></tag-name>
<tag-desc>
<header>Host</header> request header field,
or the server name matching a request if this field is not present
</tag-desc>

<tag-name><var>$hostname</var></tag-name>
<tag-desc>
host name
</tag-desc>

<tag-name><var>$http_</var><argument>name</argument></tag-name>
<tag-desc>
the <argument>name</argument> request header field
</tag-desc>

<tag-name><var>$is_args</var></tag-name>
<tag-desc>
<dq><code>?</code></dq> if a request line has arguments,
or an empty string otherwise
</tag-desc>

<tag-name><var>$limit_rate</var></tag-name>
<tag-desc>
allows for connection rate limiting
</tag-desc>

<tag-name><var>$pid</var></tag-name>
<tag-desc>
PID of the worker process
</tag-desc>

<tag-name><var>$request_method</var></tag-name>
<tag-desc>
request method, usually
<dq><code>GET</code></dq> or <dq><code>POST</code></dq>
</tag-desc>

<tag-name><var>$remote_addr</var></tag-name>
<tag-desc>
client address
</tag-desc>

<tag-name><var>$remote_port</var></tag-name>
<tag-desc>
client port
</tag-desc>

<tag-name><var>$remote_user</var></tag-name>
<tag-desc>
user name supplied with the Basic authentication
</tag-desc>

<tag-name><var>$realpath_root</var></tag-name>
<tag-desc>
<link id="root">root</link> directive's value
for the current request, with all symbolic links resolved to real paths
</tag-desc>

<tag-name><var>$request_filename</var></tag-name>
<tag-desc>
file path for the current query, based on the
<link id="root">root</link> and <link id="alias">alias</link>
directives, and the request URI
</tag-desc>

<tag-name><var>$request_body</var></tag-name>
<tag-desc>
request body
<para>
The variable's value is made available in locations
processed by the
<link doc="ngx_http_proxy_module.xml" id="proxy_pass">proxy_pass</link>
and
<link doc="ngx_http_fastcgi_module.xml" id="fastcgi_pass">fastcgi_pass</link>
directives.
</para>
</tag-desc>

<tag-name><var>$request_body_file</var></tag-name>
<tag-desc>
name of a temporary file with the request body
<para>
At the end of processing, the file needs to be removed.
To always write a request body to a file,
<link id="client_body_in_file_only">client_body_in_file_only on</link>
needs be specified.
When passing the name of a temporary file in a proxied request,
or in a request to a FastCGI server,
passing of the request body should be disabled by the
<link doc="ngx_http_proxy_module.xml"
id="proxy_pass_request_body">proxy_pass_request_body</link>
and
<link doc="ngx_http_fastcgi_module.xml"
id="fastcgi_pass_request_body">fastcgi_pass_request_body</link>
directives, respectively.
</para>
</tag-desc>

<tag-name><var>$request_uri</var></tag-name>
<tag-desc>
full original request URI (with arguments)
</tag-desc>

<tag-name><var>$query_string</var></tag-name>
<tag-desc>
same as <var>$args</var>
</tag-desc>

<tag-name><var>$scheme</var></tag-name>
<tag-desc>
request scheme, <dq><code>http</code></dq> or <dq><code>https</code></dq>
</tag-desc>

<tag-name><var>$server_protocol</var></tag-name>
<tag-desc>
request protocol, usually
<dq><code>HTTP/1.0</code></dq>
or
<dq><code>HTTP/1.1</code></dq>
</tag-desc>

<tag-name><var>$server_addr</var></tag-name>
<tag-desc>
an address of the server which accepted a request
<para>
Computing a value of this variable usually requires one system call.
To avoid a system call, the <command>listen</command> directives
must specify addresses and use the <parameter>bind</parameter> parameter
</para>
</tag-desc>

<tag-name><var>$server_name</var></tag-name>
<tag-desc>
name of the server which accepted a request
</tag-desc>

<tag-name><var>$server_port</var></tag-name>
<tag-desc>
port of the server which accepted a request
</tag-desc>

<tag-name><var>$uri</var></tag-name>
<tag-desc>
current URI in request
<para>
It may differ from an original, e.g. when doing internal redirects,
or when using index files.
</para>
</tag-desc>

</list>
</para>

</section>

</module>