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
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
|
.\" $OpenBSD: nginx.conf.5,v 1.6 2013/12/16 11:19:03 florian Exp $
.\"
.\" Copyright (C) 2002-2012 Igor Sysoev
.\" Copyright (C) 2011-2013 Nginx, Inc.
.\" Copyright (C) 2013 Florian Obser <florian@openbsd.org>
.\" Copyright (C) 2013 Ingo Schwarze <schwarze@openbsd.org>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd $Mdocdate: December 16 2013 $
.Dt NGINX.CONF 5
.Os
.Sh NAME
.Nm nginx.conf
.Nd nginx daemon configuration file
.Sh DESCRIPTION
.Xr nginx 8
.Pq pronounced Dq engine x
is an HTTP and reverse proxy server, as well as a mail proxy server.
It is known for its high performance, stability, rich feature set, simple
configuration, and low resource consumption.
.Pp
The configuration file consists of a list of configuration directives:
.Bd -offset indent -ragged
.Ar list
.Li ::=
.Op Ar directive
.Op Ar opt-ws
.Op Ar list
.Ed
.Pp
Lists may be empty, they may contain leading and trailing whitespace
and comments, and they may contain whitespace and comments between
directives.
Such whitespace is semantically insignificant.
.Pp
The syntax of a configuration directive is:
.Bd -offset indent -ragged
.Ar directive
.Li ::=
.Ar keyword
.Ar ws
.Ar arguments
.Op Ar ws
.Qq Li \&;
.Li \&|
.Ar context
.Ed
.Pp
In this case, whitespace is required to separate the keyword from
the arguments.
A context may not be followed by a semicolon, but after every other
directive, a semicolon is required, even at the end of a list.
.Pp
As a special cases of a configuration directive, the syntax of a
configuration context is:
.Bd -offset indent -ragged
.Ar context
.Li ::=
.Ar keyword
.Op Ar ws
.Qq Li \&{
.Op Ar list
.Qq Li \&}
.Ed
.Pp
Contexts may be nested, and they freely intermix with other directives
on each nesting level.
.Pp
The syntax of whitespace is:
.Bd -offset indent -ragged
.Ar ws
.Li ::=
.Ar ws-char
.Op Ar opt-ws
.Ed
.Bd -offset indent -ragged
.Ar ws-char
.Li ::=
.Aq space
.Li \&|
.Aq tab
.Li \&|
.Aq newline
.Ed
.Bd -offset indent -ragged
.Ar opt-ws
.Li ::=
.Pq Ar comment | ws-char
.Op Ar opt-ws
.Ed
.Bd -offset indent -ragged
.Ar comment
.Li ::=
.Qq #
.Op Ao non-newline character Ac ...
.Aq newline
.Ed
.Pp
Comments start with a hash character and extend to the end of the line.
They can start at the beginning of a line, after the semicolon or closing
brace at the end of a directive, or after any whitespace character,
even in the middle of a directive.
.Pp
In the following, all keywords are listed, and their arguments are
explained.
.Ss Core functionality
.Bl -tag -width Ds
.It Ic accept_mutex Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic events
.El
.Pp
If
.Ic accept_mutex
is enabled, worker processes will accept new connections by turn.
Otherwise, all worker processes will be notified about new connections, and if
volume of new connections is low, some of the worker processes may just waste
system resources.
The use of
.Cm rtsig
connection processing method requires
.Ic accept_mutex
to be enabled.
.It Ic accept_mutex_delay Ar time
.Bl -tag -width Ds -compact
.It default: 500ms
.It context: Ic events
.El
.Pp
If
.Ic accept_mutex
is enabled, specifies the maximum time during which a worker process will try to
restart accepting new connections if another worker process is currently
accepting new connections.
.It Ic daemon Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: main
.El
.Pp
Determines whether nginx should become a daemon.
Mainly used during development.
.It Ic debug_connection Ar address | Ar CIDR | Cm unix:
.Bl -tag -width Ds -compact
.It default:
.It context: Ic events
.El
.Pp
Enables debugging log for selected client connections.
Other connections will use logging level set by the
.Ic error_log
directive.
Debugged connections are specified by IPv4 or IPv6 (1.3.0, 1.2.1) address or
network.
A connection may also be specified using a hostname.
For connections using UNIX-domain sockets (1.3.0, 1.2.1), debugging log is
enabled by the
.Cm unix:
parameter.
.Bd -literal -offset indent
events {
debug_connection 127.0.0.1;
debug_connection localhost;
debug_connection 192.0.2.0/24;
debug_connection ::1;
debug_connection 2001:0db8::/32;
debug_connection unix:;
...
}
.Ed
.Pp
For this directive to work, nginx needs to be built with
.Fl -with-debug .
.It Ic debug_points Cm abort | Cm stop
.Bl -tag -width Ds -compact
.It default:
.It context: main
.El
.Pp
This directive is used for debugging.
When internal error is detected, e.g. the leak of sockets on restart of working
processes, enabling
.Ic debug_points
leads to a core file creation
.Pq Cm abort
or to stopping of a process
.Pq Cm stop
for further analysis using a system debugger.
.It Ic error_log Ar file | Cm stderr | Cm syslog Ns : Ns Cm server Ns = Ns Ar address Oo , Ar parameter Ns = Ns Ar value Oc Oo Cm debug | Cm info | Cm notice | Cm warn | Cm error | Cm crit | Cm alert | Cm emerg Oc
.Bl -tag -width Ds -compact
.It default: Pa logs/error.log Cm error
.It context: main , Ic http , Ic server , Ic location
.El
.Pp
Configures logging.
Several logs can be specified on the same level (1.5.2).
The first parameter defines a file that will store the log.
The special value
.Cm stderr
selects the standard error file.
Logging to syslog can be configured by specifying the
.Cm syslog:
prefix.
The second parameter determines the level of logging.
Log levels above are listed in the order of increasing severity.
Setting a certain log level will cause all messages of the specified and more
severe log levels to be logged.
For example, the default level
.Cm error
will cause
.Cm error ,
.Cm crit ,
.Cm alert ,
and
.Cm emerg
messages to be logged.
If this parameter is omitted then
.Cm error
is used.
For
.Cm debug
logging to work, nginx needs to be built with
.Fl -with-debug .
The following parameters configure logging to syslog:
.Bl -tag -width Ds
.It Cm server Ns = Ns Ar address
Defines an address of a syslog server.
An address can be specified as a domain name or IP address, and an optional
port, or as a UNIX-domain socket path specified after the
.Cm unix:
prefix.
If port is not specified, the port 514 is used.
If a domain name resolves to several IP addresses, the first resolved address is
used.
.It Cm facility Ns = Ns Ar string
Sets facility of syslog messages, as defined in
RFC 3164.
Facility can be one of
.Cm kern ,
.Cm user ,
.Cm mail ,
.Cm daemon ,
.Cm auth ,
.Cm intern ,
.Cm lpr ,
.Cm news ,
.Cm uucp ,
.Cm clock ,
.Cm authpriv ,
.Cm ftp ,
.Cm ntp ,
.Cm audit ,
.Cm alert ,
.Cm cron ,
.Cm local0 No .. Cm local7.
Default is
.Cm local7 .
.It Cm tag Ns = Ns Ar string
Sets tag of syslog messages.
Default is
.Qq nginx .
.El
.Pp
Example syslog configuration:
.Bd -literal -offset indent
error_log syslog:server=192.168.1.1 debug;
error_log syslog:server=unix:/var/log/nginx.sock;
error_log syslog:server=[2001:db8::1]:12345,facility=local7,tag=nginx error;
.Ed
.It Ic env Ar variable Ns Oo = Ns Ar value Oc
.Bl -tag -width Ds -compact
.It default: Ev TZ
.It context: main
.El
.Pp
By default, nginx removes all environment variables inherited from its parent
process except the
.Ev TZ
variable.
This directive allows preserving some of the inherited variables, changing their
values, or creating new environment variables.
These variables are then:
.Bl -bullet
.It
inherited during a live upgrade of an executable file;
.It
used by the
.Sx Module ngx_http_perl_module
module;
.It
used by worker processes.
One should bear in mind that controlling system libraries in this way is not
always possible as it is common for libraries to check variables only during
initialization, well before they can be set using this directive.
An exception from this is an above mentioned live upgrade of an executable file.
.El
.Pp
The
.Ev TZ
variable is always inherited and available to the
.Sx Module ngx_http_perl_module
module, unless it is configured explicitly.
Usage example:
.Bd -literal -offset indent
env MALLOC_OPTIONS;
env PERL5LIB=/data/site/modules;
env OPENSSL_ALLOW_PROXY_CERTS=1;
.Ed
.Pp
The
.Ev NGINX
environment variable is used internally by nginx and should not be set directly
by the user.
.It Ic events Brq No ...
.Bl -tag -width Ds -compact
.It default:
.It context: main
.El
.Pp
Provides the configuration file context in which the directives that affect
connection processing are specified.
.It Ic include Ar file | Ar mask
.Bl -tag -width Ds -compact
.It default:
.It context: any
.El
.Pp
Includes another
.Ar file ,
or files matching the specified
.Ar mask ,
into configuration.
Included files should consist of syntactically correct directives and blocks.
Usage example:
.Bd -literal -offset indent
include mime.types;
include vhosts/*.conf;
.Ed
.It Ic lock_file Ar file
.Bl -tag -width Ds -compact
.It default: Pa logs/nginx.lock
.It context: main
.El
.Pp
nginx uses the locking mechanism to implement
.Ic accept_mutex
and serialize access to shared memory.
On most systems the locks are implemented using atomic operations, and this
directive is ignored.
On other systems the lock file mechanism is used.
This directive specifies a prefix for the names of lock files.
.It Ic master_process Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: main
.El
.Pp
Determines whether worker processes are started.
This directive is intended for nginx developers.
.It Ic multi_accept Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic events
.El
.Pp
If
.Ic multi_accept
is disabled, a worker process will accept one new connection at a time.
Otherwise, a worker process will accept all new connections at a time.
The directive is ignored if
.Cm kqueue
connection processing method is used, because it reports the number of new
connections waiting to be accepted.
The use of
.Cm rtsig
connection processing method automatically enables
.Ic multi_accept .
.It Ic pcre_jit Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: main
.El
.Pp
Enables or disables the use of just-in-time compilation (PCRE JIT) for the
regular expressions known by the time of configuration parsing.
PCRE JIT can speed up processing of regular expressions significantly.
The JIT is available in PCRE libraries starting from version 8.20 built with the
.Fl -enable-jit
configuration parameter.
When the PCRE library is built with nginx
.Pq Fl -with-pcre Ns = Ns ,
the JIT support is enabled via the
.Fl -with-pcre-jit
configuration parameter.
.It Ic pid Ar file
.Bl -tag -width Ds -compact
.It default: Pa nginx.pid
.It context: main
.El
.Pp
Defines a
.Ar file
that will store the process ID of the main process.
.It Ic ssl_engine Ar device
.Bl -tag -width Ds -compact
.It default:
.It context: main
.El
.Pp
Defines the name of the hardware SSL accelerator.
.It Ic timer_resolution Ar interval
.Bl -tag -width Ds -compact
.It default:
.It context: main
.El
.Pp
Reduces timer resolution in worker processes, thus reducing the number of
.Fn gettimeofday
system calls made.
By default,
.Fn gettimeofday
is called each time a kernel event is received.
With reduced resolution,
.Fn gettimeofday
is only called once per specified
.Ar interval .
Example:
.Bd -literal -offset indent
timer_resolution 100ms;
.Ed
.Pp
Internal implementation of the interval depends on the method used:
.Bl -bullet
.It
the
.Dv EVFILT_TIMER
filter if
.Cm kqueue
is used;
.It
.Fn timer_create
if
.Cm eventport
is used;
.It
.Fn setitimer
otherwise.
.El
.It Ic use Ar method
.Bl -tag -width Ds -compact
.It default:
.It context: Ic events
.El
.Pp
Specifies the
connection processing
.Ar method
to use.
There is normally no need to specify it explicitly, because nginx will by
default use the most efficient method.
.It Ic user Ar user Oo Ar group Oc
.Bl -tag -width Ds -compact
.It default: nobody nobody
.It context: main
.El
.Pp
Defines
.Ar user
and
.Ar group
credentials used by worker processes.
If
.Ar group
is omitted, a group whose name equals that of
.Ar user
is used.
.It Ic worker_aio_requests Ar number
.Bl -tag -width Ds -compact
.It default: 32
.It context: Ic events
.El
.Pp
When using
.Ic aio
with the
.Cm epoll
connection processing method, sets the maximum
.Ar number
of outstanding asynchronous I/O operations for a single worker process.
.It Ic worker_connections Ar number
.Bl -tag -width Ds -compact
.It default: 512
.It context: Ic events
.El
.Pp
Sets the maximum number of simultaneous connections that can be opened by a
worker process.
It should be kept in mind that this number includes all connections (e.g.
connections with proxied servers, among others), not only connections with
clients.
Another consideration is that the actual number of simultaneous connections
cannot exceed the current limit on the maximum number of open files, which can
be changed by
.Ic worker_rlimit_nofile .
.It Ic worker_cpu_affinity Ar cpumask No ...
.Bl -tag -width Ds -compact
.It default:
.It context: main
.El
.Pp
Binds worker processes to the sets of CPUs.
Each CPU set is represented by a bitmask of allowed CPUs.
There should be a separate set defined for each of the worker processes.
By default, worker processes are not bound to any specific CPUs.
For example,
.Bd -literal -offset indent
worker_processes 4;
worker_cpu_affinity 0001 0010 0100 1000;
.Ed
.Pp
binds each worker process to a separate CPU, while
.Bd -literal -offset indent
worker_processes 2;
worker_cpu_affinity 0101 1010;
.Ed
.Pp
binds the first worker process to CPU0/CPU2, and the second worker process to
CPU1/CPU3.
The second example is suitable for hyper-threading.
The directive is only available on FreeBSD and Linux.
.It Ic worker_priority Ar number
.Bl -tag -width Ds -compact
.It default: 0
.It context: main
.El
.Pp
Defines the scheduling priority for worker processes like it is done by the
.Ic nice
command: a negative
.Ar number
means higher priority.
Allowed range normally varies from -20 to 20.
Example:
.Bd -literal -offset indent
worker_priority -10;
.Ed
.It Ic worker_processes Ar number | Cm auto
.Bl -tag -width Ds -compact
.It default: 1
.It context: main
.El
.Pp
Defines the number of worker processes.
The optimal value depends on many factors including (but not limited to) the
number of CPU cores, the number of hard disk drives that store data, and load
pattern.
When one is in doubt, setting it to the number of available CPU cores would be a
good start (the value
.Cm auto
will try to autodetect it).
The
.Cm auto
parameter is supported starting from versions 1.3.8 and 1.2.5.
.It Ic worker_rlimit_core Ar size
.Bl -tag -width Ds -compact
.It default:
.It context: main
.El
.Pp
Changes the limit on the largest size of a core file
.Pq Dv RLIMIT_CORE
for worker processes.
Used to increase the limit without restarting the main process.
.It Ic worker_rlimit_nofile Ar number
.Bl -tag -width Ds -compact
.It default:
.It context: main
.El
.Pp
Changes the limit on the maximum number of open files
.Pq Dv RLIMIT_NOFILE
for worker processes.
Used to increase the limit without restarting the main process.
.It Ic worker_rlimit_sigpending Ar number
.Bl -tag -width Ds -compact
.It default:
.It context: main
.El
.Pp
On systems that support
.Cm rtsig
connection processing method, changes the limit on the number of signals that
may be queued
.Pq Dv RLIMIT_SIGPENDING
for worker processes.
Used to increase the limit without restarting the main process.
.It Ic working_directory Ar directory
.Bl -tag -width Ds -compact
.It default:
.It context: main
.El
.Pp
Defines the current working directory for a worker process.
It is primarily used when writing a core-file, in which case a worker process
should have write permission for the specified directory.
.El
.Ss Module ngx_http_core_module
.Bl -tag -width Ds
.It Ic aio Cm on | Cm off | Cm sendfile
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables the use of asynchronous file I/O (AIO) on FreeBSD and Linux.
On FreeBSD, AIO can be used starting from FreeBSD 4.3.
AIO can either be linked statically into a kernel:
.Bd -literal -offset indent
options VFS_AIO
.Ed
.Pp
or loaded dynamically as a kernel loadable module:
.Bd -literal -offset indent
kldload aio
.Ed
.Pp
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, which can impact overall performance negatively.
This limitation has been removed in FreeBSD 6.4-STABLE in 2009, and in FreeBSD
7.
However, starting from FreeBSD 5.3 it is possible to enable AIO without the
penalty of running the networking subsystem under a Giant lock-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
.Pa /var/log/messages
.Bd -literal -offset indent
WARNING: Network stack Giant-free, but aio requires Giant.
Consider adding 'options NET_WITH_GIANT' or setting debug.mpsafenet=0
.Ed
.Pp
and can safely be ignored.
The requirement to use the Giant lock with AIO is related to the fact that
FreeBSD supports asynchronous calls
.Fn aio_read
and
.Fn aio_write
when working with sockets.
However, since nginx uses AIO only for disk I/O, no problems should arise.
For AIO to work,
.Ic sendfile
needs to be disabled:
.Bd -literal -offset indent
location /video/ {
sendfile off;
aio on;
output_buffers 1 64k;
}
.Ed
.Pp
In addition, starting from FreeBSD 5.2.1 and nginx 0.8.12, AIO can also be used
to pre-load data for
.Fn sendfile :
.Bd -literal -offset indent
location /video/ {
sendfile on;
tcp_nopush on;
aio sendfile;
}
.Ed
.Pp
In this configuration,
.Fn sendfile
is called with the
.Dv SF_NODISKIO
flag which causes it not to block on disk I/O, but, instead, report back that
the data are not in memory.
nginx then initiates an asynchronous data load by reading one byte.
On the first read, the FreeBSD kernel loads the first 128K bytes of a file into
memory, although next reads will only load data in 16K chunks.
This can be changed using the
.Ic read_ahead
directive.
On Linux, AIO can be used starting from kernel version 2.6.22.
Also, it is necessary to enable
.Ic directio ,
or otherwise reading will be blocking:
.Bd -literal -offset indent
location /video/ {
aio on;
directio 512;
output_buffers 1 128k;
}
.Ed
.Pp
On Linux,
.Ic directio
can only be used for reading blocks that are aligned on 512-byte boundaries (or
4K for XFS).
File's unaligned end is read 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
.Ic sendfile
explicitly, as it is turned off automatically when
.Ic directio
is used.
.It Ic alias Ar path
.Bl -tag -width Ds -compact
.It default:
.It context: Ic location
.El
.Pp
Defines a replacement for the specified location.
For example, with the following configuration
.Bd -literal -offset indent
location /i/ {
alias /data/w3/images/;
}
.Ed
.Pp
on request of
.Pa /i/top.gif ,
the file
.Pa /data/w3/images/top.gif
will be sent.
The
.Ar path
value can contain variables, except
.Va $document_root
and
.Va $realpath_root .
If
.Ic alias
is used inside a location defined with a regular expression then such regular
expression should contain captures and
.Ic alias
should refer to these captures (0.7.40), for example:
.Bd -literal -offset indent
location ~ ^/users/(.+\\.(?:gif |jpe?g |png))$ {
alias /data/w3/images/$1;
}
.Ed
.Pp
When location matches the last part of the directive's value:
.Bd -literal -offset indent
location /images/ {
alias /data/w3/images/;
}
.Ed
.Pp
it is better to use the
.Ic root
directive instead:
.Bd -literal -offset indent
location /images/ {
root /data/w3;
}
.Ed
.It Ic chunked_transfer_encoding Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server , Ic location
.El
.Pp
Allows disabling chunked transfer encoding in HTTP/1.1.
It may come in handy when using a software failing to support chunked encoding
despite the standard's requirement.
.It Ic client_body_buffer_size Ar size
.Bl -tag -width Ds -compact
.It default: 8k | 16k
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets buffer size for reading client request body.
In case the request body is larger than the buffer, the whole body or only its
part is written to a
.Ic client_body_temp_path
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.
.It Ic client_body_in_file_only Cm on | Cm clean | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Determines whether nginx should save the entire client request body into a file.
This directive can be used during debugging, or when using the
.Va $request_body_file
variable, or the
methods
.Ic $r->request_body_file
method of the module
.Sx Module ngx_http_perl_module .
When set to the value
.Cm on ,
temporary files are not removed after request processing.
The value
.Cm clean
will cause the temporary files left after request processing to be removed.
.It Ic client_body_in_single_buffer Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Determines whether nginx should save the entire client request body in a single
buffer.
The directive is recommended when using the
.Va $request_body
variable, to save the number of copy operations involved.
.It Ic client_body_temp_path Ar path Oo Ar level1 Oo Ar level2 Oo Ar level3 Oc Oc Oc
.Bl -tag -width Ds -compact
.It default: client_body_temp
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines a directory for storing temporary files holding client request bodies.
Up to three-level subdirectory hierarchy can be used under the specified
directory.
For example, in the following configuration
.Bd -literal -offset indent
client_body_temp_path /spool/nginx/client_temp 1 2;
.Ed
.Pp
a path to a temporary file might look like this:
.Pa /spool/nginx/client_temp/7/45/00000123457
.It Ic client_body_timeout Ar time
.Bl -tag -width Ds -compact
.It default: 60s
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines a timeout for reading client request body.
The timeout is set only for a period 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 408 (Request
Time-out) error is returned to the client.
.It Ic client_header_buffer_size Ar size
.Bl -tag -width Ds -compact
.It default: 1k
.It context: Ic http , Ic server
.El
.Pp
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 does not fit into this buffer then
larger buffers, configured by the
.Ic large_client_header_buffers
directive, are allocated.
.It Ic client_header_timeout Ar time
.Bl -tag -width Ds -compact
.It default: 60s
.It context: Ic http , Ic server
.El
.Pp
Defines a timeout for reading client request header.
If a client does not transmit the entire header within this time, the 408
(Request Time-out) error is returned to the client.
.It Ic client_max_body_size Ar size
.Bl -tag -width Ds -compact
.It default: 1m
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the maximum allowed size of the client request body, specified in the
Content-Length request header field.
If the size in a request exceeds the configured value, the 413 (Request Entity
Too Large) error is returned to the client.
Please be aware that browsers cannot correctly display this error.
Setting
.Ar size
to 0 disables checking of client request body size.
.It Ic connection_pool_size Ar size
.Bl -tag -width Ds -compact
.It default: 256
.It context: Ic http , Ic server
.El
.Pp
Allows accurate tuning of per-connection memory allocations.
This directive has minimal impact on performance and should not generally be
used.
.It Ic default_type Ar mime-type
.Bl -tag -width Ds -compact
.It default: text/plain
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines the default MIME type of a response.
Mapping of file name extensions to MIME types can be set with the
.Ic types
directive.
.It Ic directio Ar size | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables the use of the
.Dv O_DIRECT
flag (FreeBSD, Linux), the
.Dv F_NOCACHE
flag (Mac OS X), or the
.Fn directio
function (Solaris), when reading files that are larger than or equal to the
specified
.Ar size.
The directive automatically disables (0.7.15) the use of
.Ic sendfile
for a given request.
It can be useful for serving large files:
.Bd -literal -offset indent
directio 4m;
.Ed
.Pp
or when using
.Ic aio
on Linux.
.It Ic directio_alignment Ar size
.Bl -tag -width Ds -compact
.It default: 512
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the alignment for
.Ic directio.
In most cases, a 512-byte alignment is enough.
However, when using XFS under Linux, it needs to be increased to 4K.
.It Ic disable_symlinks Cm off
.It Ic disable_symlinks Cm on | Cm if_not_owner Oo Cm from Ns = Ns Ar part Oc
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Determines how symbolic links should be treated when opening files:
.Bl -tag -width Ds
.It Cm off
Symbolic links in the pathname are allowed and not checked.
This is the default behavior.
.It Cm on
If any component of the pathname is a symbolic link, access to a file is denied.
.It Cm if_not_owner
Access to a file is denied if any component of the pathname is a symbolic link,
and the link and object that the link points to have different owners.
.It Cm from Ns = Ns Ar part
When checking symbolic links (parameters
.Cm on
and
.Cm if_not_owner ) ,
all components of the pathname are normally checked.
Checking of symbolic links in the initial part of the pathname may be avoided by
specifying additionally the
.Cm from Ns = Ns Ar part
parameter.
In this case, symbolic links are checked only from the pathname component that
follows the specified initial part.
If the value is not an initial part of the pathname checked, the whole pathname
is checked as if this parameter was not specified at all.
If the value matches the whole file name, symbolic links are not checked.
The parameter value can contain variables.
.El
.Pp
Example:
.Bd -literal -offset indent
disable_symlinks on from=$document_root;
.Ed
.Pp
This directive is only available on systems that have the
.Fn openat
and
.Fn fstatat
interfaces.
Such systems include modern versions of FreeBSD, Linux, and Solaris.
Parameters
.Cm on
and
.Cm if_not_owner
add a processing overhead.
On systems that do not support opening of directories only for search, to use
these parameters it is required that worker processes have read permissions for
all directories being checked.
The
.Sx Module ngx_http_autoindex_module ,
.Sx Module ngx_http_random_index_module ,
and
.Sx Module ngx_http_dav_module
modules currently ignore this directive.
.It Ic error_page Ar code No ... Oo = Ns Oo Ar response Oc Oc Ar uri
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location , Ic if in location
.El
.Pp
Defines the URI that will be shown for the specified errors.
.Ic error_page
directives are inherited from the previous level only if there are no
.Ic error_page
directives defined on the current level.
A
.Ar uri
value can contain variables.
Example:
.Bd -literal -offset indent
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
.Ed
.Pp
Furthermore, it is possible to change the response code to another using the
.Ar =response
syntax, for example:
.Bd -literal -offset indent
error_page 404 =200 /empty.gif;
.Ed
.Pp
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 the code it returns:
.Bd -literal -offset indent
error_page 404 = /404.php;
.Ed
.Pp
It is also possible to use redirects for error processing:
.Bd -literal -offset indent
error_page 403 http://example.com/forbidden.html;
error_page 404 =301 http://example.com/notfound.html;
.Ed
.Pp
In this case, by default, the response code 302 is returned to the client.
It can only be changed to one of the redirect status codes (301, 302, 303, and
307).
If there is no need to change URI during internal redirection it is possible to
pass error processing into a named location:
.Bd -literal -offset indent
location / {
error_page 404 = @fallback;
}
location @fallback {
proxy_pass http://backend;
}
.Ed
.Pp
If
.Ar uri
processing leads to an error, the status code of the last occurred error is
returned to the client.
.It Ic etag Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables automatic generation of the ETag response header field for
static resources.
.It Ic http Brq No ...
.Bl -tag -width Ds -compact
.It default:
.It context: main
.El
.Pp
Provides the configuration file context in which the HTTP server directives are
specified.
.It Ic if_modified_since Cm off | Cm exact | Cm before
.Bl -tag -width Ds -compact
.It default: Cm exact
.It context: Ic http , Ic server , Ic location
.El
.Pp
Specifies how to compare modification time of a response with the time in the
If-Modified-Since request header field:
.Bl -tag -width Ds
.It Cm off
the If-Modified-Since request header field is ignored (0.7.34);
.It Cm exact
exact match;
.It Cm before
modification time of a response is less than or equal to the time in the
If-Modified-Since request header field.
.El
.It Ic ignore_invalid_headers Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server
.El
.Pp
Controls whether header fields with invalid names should be ignored.
Valid names are composed of English letters, digits, hyphens, and possibly
underscores (as controlled by the
.Ic underscores_in_headers
directive).
A directive can be specified on the
.Ic server
level in the default server.
In this case, its value will cover all virtual servers listening on the same
address and port.
.It Ic internal
.Bl -tag -width Ds -compact
.It default:
.It context: Ic location
.El
.Pp
Specifies that a given location can only be used for internal requests.
For external requests, the client error 404 (Not Found) is returned.
Internal requests are the following:
.Bl -bullet
.It
requests redirected by the
.Ic error_page ,
.Ic index ,
.Ic random_index ,
and
.Ic try_files
directives;
.It
requests redirected by the X-Accel-Redirect response header field from an
upstream server;
.It
subrequests formed by the
.Ic include virtual
command of the
.Sx Module ngx_http_ssi_module
module and by the
.Sx Module ngx_http_addition_module
module directives;
.It
requests changed by the
.Ic rewrite
directive.
.El
.Pp
Example:
.Bd -literal -offset indent
error_page 404 /404.html;
location /404.html {
internal;
}
.Ed
.Pp
There is a limit of 10 internal redirects per request to prevent request
processing cycles that can occur in incorrect configurations.
If this limit is reached, the error 500 (Internal Server Error) is returned.
In such cases, the rewrite or internal redirection cycle message can be seen in
the error log.
.It Ic keepalive_disable Cm none | Ar browser No ...
.Bl -tag -width Ds -compact
.It default: Cm msie6
.It context: Ic http , Ic server , Ic location
.El
.Pp
Disables keep-alive connections with misbehaving browsers.
The
.Ar browser
parameters specify which browsers will be affected.
The value
.Cm msie6
disables keep-alive connections with old versions of MSIE, once a POST request
is received.
The value
.Cm safari
disables keep-alive connections with Safari and Safari-like browsers on Mac OS X
and Mac OS X-like operating systems.
The value
.Cm none
enables keep-alive connections with all browsers.
Prior to version 1.1.18, the value
.Cm safari
matched all Safari and Safari-like browsers on all operating systems, and
keep-alive connections with them were disabled by default.
.It Ic keepalive_requests Ar number
.Bl -tag -width Ds -compact
.It default: 100
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the maximum number of requests that can be served through one keep-alive
connection.
After the maximum number of requests are made, the connection is closed.
.It Ic keepalive_timeout Ar timeout Oo Ar header_timeout Oc
.Bl -tag -width Ds -compact
.It default: 75s
.It context: Ic http , Ic server , Ic location
.El
.Pp
The first parameter sets a timeout during which a keep-alive client connection
will stay open on the server side.
The zero value disables keep-alive client connections.
The optional second parameter sets a value in the Keep-Alive: timeout=time
response header field.
Two parameters may differ.
The Keep-Alive: timeout=time header field is recognized by Mozilla and
Konqueror.
MSIE closes keep-alive connections by itself in about 60 seconds.
.It Ic large_client_header_buffers Ar number Ar size
.Bl -tag -width Ds -compact
.It default: 4 8k
.It context: Ic http , Ic server
.El
.Pp
Sets the maximum
.Ar number
and
.Ar size
of buffers used for reading large client request header.
A request line cannot exceed the size of one buffer, or the 414 (Request-URI Too
Large) error is returned to the client.
A request header field cannot exceed the size of one buffer as well, or the 400
(Bad Request) error is returned to the client.
Buffers are allocated only on demand.
By default, the buffer size is equal to 8K bytes.
If after the end of request processing a connection is transitioned into the
keep-alive state, these buffers are released.
.It Ic limit_except Ar method No ... Brq No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic location
.El
.Pp
Limits allowed HTTP methods inside a location.
The
.Ar method
parameter can be one of the following:
.Cm GET ,
.Cm HEAD ,
.Cm POST ,
.Cm PUT ,
.Cm DELETE ,
.Cm MKCOL ,
.Cm COPY ,
.Cm MOVE ,
.Cm OPTIONS ,
.Cm PROPFIND ,
.Cm PROPPATCH ,
.Cm LOCK ,
.Cm UNLOCK ,
or
.Cm PATCH.
Allowing the
.Cm GET
method makes the
.Cm HEAD
method also allowed.
Access to other methods can be limited using the
.Sx Module ngx_http_access_module
and
.Sx Module ngx_http_auth_basic_module
modules directives:
.Bd -literal -offset indent
limit_except GET {
allow 192.168.1.0/32;
deny all;
}
.Ed
.Pp
Please note that this will limit access to all methods except
.Cm GET
and
.Cm HEAD .
.It Ic limit_rate Ar rate
.Bl -tag -width Ds -compact
.It default: 0
.It context: Ic http , Ic server , Ic location , Ic if in location
.El
.Pp
Limits the rate of response transmission to a client.
The
.Ar rate
is specified in bytes per second.
The zero value disables rate limiting.
The limit is set per a request, and so if a client simultaneously opens two
connections, the overall rate will be twice as much as the specified limit.
Rate limit can also be set in the
.Va $limit_rate
variable.
It may be useful in cases where rate should be limited depending on a certain
condition:
.Bd -literal -offset indent
server {
if ($slow) {
set $limit_rate 4k;
}
...
}
.Ed
.Pp
Rate limit can also be set in the X-Accel-Limit-Rate header field of a proxied
server response.
This capability can be disabled using the
.Ic proxy_ignore_headers
and
.Ic fastcgi_ignore_headers
directives.
.It Ic limit_rate_after Ar size
.Bl -tag -width Ds -compact
.It default: 0
.It context: Ic http , Ic server , Ic location , Ic if in location
.El
.Pp
Sets the initial amount after which the further transmission of a response to a
client will be rate limited.
Example:
.Bd -literal -offset indent
location /flv/ {
flv;
limit_rate_after 500k;
limit_rate 50k;
}
.Ed
.It Ic lingering_close Cm off | Cm on | Cm always
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server , Ic location
.El
.Pp
Controls how nginx closes client connections.
The default value
.Cm on
instructs nginx to
.Ic lingering_timeout
wait for and
.Ic lingering_time
process additional data from a client before fully closing a connection, but
only if heuristics suggests that a client may be sending more data.
The value
.Cm always
will cause nginx to unconditionally wait for and process additional client data.
The value
.Cm off
tells nginx to never wait for more data and close the connection immediately.
This behavior breaks the protocol and should not be used under normal
circumstances.
.It Ic lingering_time Ar time
.Bl -tag -width Ds -compact
.It default: 30s
.It context: Ic http , Ic server , Ic location
.El
.Pp
When
.Ic lingering_close
is in effect, this directive specifies the maximum time during which nginx will
process (read and ignore) additional data coming from a client.
After that, the connection will be closed, even if there will be more data.
.It Ic lingering_timeout Ar time
.Bl -tag -width Ds -compact
.It default: 5s
.It context: Ic http , Ic server , Ic location
.El
.Pp
When
.Ic lingering_close
is in effect, this directive specifies the maximum waiting time for more client
data to arrive.
If data are not received during this time, the connection is closed.
Otherwise, the data are read and ignored, and nginx starts waiting for more data
again.
The wait-read-ignore cycle is repeated, but no longer than specified by the
.Ic lingering_time
directive.
.It Ic listen Ar address Ns Oo : Ns Ar port Oc Oo Cm default_server Oc \
Oo Cm ssl Oc Oo Cm spdy Oc Oo Cm setfib Ns = Ns Ar number Oc \
Oo Cm backlog Ns = Ns Ar number Oc Oo Cm rcvbuf Ns = Ns Ar size Oc \
Oo Cm sndbuf Ns = Ns Ar size Oc \
Oo Cm accept_filter Ns = Ns Ar filter Oc \
Oo Cm deferred Oc Oo Cm bind Oc \
Oo Cm ipv6only Ns = Ns Cm on | Cm off Oc \
Oo Cm so_keepalive Ns = Ns Cm on | Cm off | \
Oo Ar keepidle Ns Oc : Ns Oo Ar keepintvl Oc : Ns Oo Ar keepcnt Oc Oc
.It Ic listen Ar port Oo Cm default_server Oc Oo Cm ssl Oc \
Oo Cm spdy Oc Oo Cm setfib Ns = Ns Ar number Oc \
Oo Cm backlog Ns = Ns Ar number Oc Oo Cm rcvbuf Ns = Ns Ar size Oc \
Oo Cm sndbuf Ns = Ns Ar size Oc \
Oo Cm accept_filter Ns = Ns Ar filter Oc \
Oo Cm deferred Oc Oo Cm bind Oc \
Oo Cm ipv6only Ns = Ns Cm on | Cm off Oc \
Oo Cm so_keepalive Ns = Ns Cm on | Cm off | \
Oo Ar keepidle Oc : Ns Oo Ar keepintvl Oc : Ns Oo Ar keepcnt Oc Oc
.It Ic listen Cm unix : Ns Ar path Oo Cm default_server Oc \
Oo Cm ssl Oc Oo Cm spdy Oc Oo Cm backlog Ns = Ns Ar number Oc \
Oo Cm rcvbuf Ns = Ns Ar size Oc \
Oo Cm sndbuf Ns = Ns Ar size Oc \
Oo Cm accept_filter Ns = Ns Ar filter Oc \
Oo Cm deferred Oc Oo Cm bind Oc \
Oo Cm so_keepalive Ns = Ns Cm on | Cm off | \
Oo Ar keepidle Oc : Ns Oo Ar keepintvl Oc : Ns Oo Ar keepcnt Oc Oc
.Pp
.Bl -tag -width Ds -compact
.It default: *:80 | *:8000
.It context: Ic server
.El
.Pp
Sets the
.Ar address
and
.Ar port
for IP, or the
.Ar path
for a UNIX-domain socket on which the server will accept requests.
Both
.Ar address
and
.Ar port ,
or only
.Ar address
or only
.Ar port
can be specified.
An
.Ar address
may also be a hostname, for example:
.Bd -literal -offset indent
listen 127.0.0.1:8000;
listen 127.0.0.1;
listen 8000;
listen *:8000;
listen localhost:8000;
.Ed
.Pp
IPv6 addresses (0.7.36) are specified in square brackets:
.Bd -literal -offset indent
listen [::]:8000;
listen [::1];
.Ed
.Pp
UNIX-domain sockets (0.8.21) are specified with the
.Cm unix:
prefix:
.Bd -literal -offset indent
listen unix:/var/run/nginx.sock;
.Ed
.Pp
If only
.Ar address
is given, the port 80 is used.
If the directive is not present then either
.Ic *:80
is used if nginx runs with the superuser privileges, or
.Ic *:8000
otherwise.
The
.Cm default_server
parameter, if present, will cause the server to become the default server for
the specified
.Ar address Ns : Ns Ar port
pair.
If none of the directives have the
.Cm default_server
parameter then the first server with the
.Ar address Ns : Ns Ar port
pair will be the default server for this pair.
In versions prior to 0.8.21 this parameter is named simply
.Cm default .
The
.Ar ssl
parameter (0.7.14) allows specifying that all connections accepted on this port
should work in SSL mode.
This allows for a more compact configuration for the server that handles both
HTTP and HTTPS requests.
The
.Cm spdy
parameter (1.3.15) allows accepting SPDY connections on this port.
Normally, for this to work the
.Ar ssl
parameter should be specified as well, but nginx can also be configured to
accept SPDY connections without SSL.
A
.Ic listen
directive can have several additional parameters specific to socket-related
system calls.
These parameters can be specified in any
.Ic listen
directive, but only once for a given
.Ar address Ns : Ns Ar port
pair.
In versions prior to 0.8.21, they could only be specified in the
.Ic listen
directive together with the
.Cm default
parameter.
.Bl -tag -width Ds
.It Cm setfib Ns = Ns Ar number
this parameter (0.8.44) sets the associated routing table, FIB (the
.Dv SO_SETFIB
option) for the listening socket.
This currently works only on FreeBSD.
.It Cm backlog Ns = Ns Ar number
sets the
.Cm backlog
parameter in the
.Fn listen
call that limits the maximum length for the queue of pending connections.
By default,
.Cm backlog
is set to -1 on FreeBSD and Mac OS X, and to 511 on other platforms.
.It Cm rcvbuf Ns = Ns Ar size
sets the receive buffer size (the
.Dv SO_RCVBUF
option) for the listening socket.
.It Cm sndbuf Ns = Ns Ar size
sets the send buffer size (the
.Dv SO_SNDBUF
option) for the listening socket.
.It Cm accept_filter Ns = Ns Ar filter
sets the name of accept filter (the
.Dv SO_ACCEPTFILTER
option) for the listening socket that filters incoming connections before
passing them to
.Fn accept.
This works only on FreeBSD and NetBSD_5.0+.
Possible values are
.Cm dataready
and
.Cm httpready .
.It Cm deferred
instructs to use a deferred
.Fn accept
(the
.Dv TCP_DEFER_ACCEPT
socket option) on Linux.
.It Cm bind
instructs to make a separate
.Fn bind
call for a given
.Ar address Ns : Ns Ar port
pair.
This is useful because if there are several
.Ic listen
directives with the same port but different addresses, and one of the
.Ic listen
directives listens on all addresses for the given port
.Pq * Ns : Ns Ar port ,
nginx will
.Fn bind
only to
.Qq * Ns : Ns Ar port .
It should be noted that the
.Fn getsockname
system call will be made in this case to determine the address that accepted the
connection.
If the
.Cm backlog ,
.Cm rcvbuf ,
.Cm sndbuf ,
.Cm accept_filter ,
.Cm deferred ,
or
.Cm so_keepalive
parameters are used then for a given
.Ar address Ns : Ar port
pair a separate
.Fn bind
call will always be made.
.It Cm ipv6only Ns = Ns Cm on | Cm off
this parameter (0.7.42) determines (via the
.Dv IPV6_V6ONLY
socket option) whether an IPv6 socket listening on a wildcard address
.Op ::
will accept only IPv6 connections or both IPv6 and IPv4 connections.
This parameter is turned on by default.
It can only be set once on start.
Prior to version 1.3.4, if this parameter was omitted then the operating
system's settings were in effect for the socket.
.It Cm so_keepalive Ns = Ns Cm on | Cm off | \
Oo Ar keepidle Oc : Ns Oo Ar keepintvl Oc : Ns Oo Ar keepcnt Oc
this parameter (1.1.11) configures the TCP keepalive behavior for the listening
socket.
If this parameter is omitted then the operating system's settings will be in
effect for the socket.
If it is set to the value
.Cm on ,
the
.Dv SO_KEEPALIVE
option is turned on for the socket.
If it is set to the value
.Cm off ,
the
.Dv SO_KEEPALIVE
option is turned off for the socket.
Some operating systems support setting of TCP keepalive parameters on a
per-socket basis using the
.Dv TCP_KEEPIDLE ,
.Dv TCP_KEEPINTVL ,
and
.Dv TCP_KEEPCNT
socket options.
On such systems (currently, Linux_2.4+, NetBSD_5+, and FreeBSD_9.0-STABLE), they
can be configured using the
.Ar keepidle ,
.Ar keepintvl ,
and
.Ar keepcnt
parameters.
One or two parameters may be omitted, in which case the system default setting
for the corresponding socket option will be in effect.
For example,
.Bd -literal -offset indent
so_keepalive=30m::10
.Ed
.Pp
will set the idle timeout
.Pq Dv TCP_KEEPIDLE
to 30 minutes, leave the probe interval
.Pq Dv TCP_KEEPINTVL
at its system default, and set the probes count
.Pq Dv TCP_KEEPCNT
to 10 probes.
.El
.Pp
Example:
.Bd -literal -offset indent
listen 127.0.0.1 default_server accept_filter=dataready backlog=1024;
.Ed
.It Ic location Oo Cm = | Cm ~ | Cm ~* | Cm ^~ Oc Ar uri Brq No ...
.It Ic location Cm @ Ar name Brq No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic server , Ic location
.El
.Pp
Sets configuration depending on a request URI.
The matching is performed against a normalized URI, after decoding the text
encoded in the
.Qq %XX
form, resolving references to relative path components
.Qo . Qc
and
.Qq .. ,
and possible
.Ic merge_slashes
compression
of two or more adjacent slashes into a single slash.
A location can either be defined by a prefix string, or by a regular expression.
Regular expressions are specified with the preceding
.Qq ~*
modifier (for case-insensitive matching), or the
.Qq ~
modifier (for case-sensitive matching).
To find location matching a given request, nginx first checks locations defined
using the prefix strings (prefix locations).
Among them, the location with the longest matching prefix is selected and
remembered.
Then regular expressions are checked, in the order of their appearance in the
configuration file.
The search of regular expressions terminates on the first match, and the
corresponding configuration is used.
If no match with a regular expression is found then the configuration of the
prefix location remembered earlier is used.
.Ic location
blocks can be nested, with some exceptions mentioned below.
For case-insensitive operating systems such as Mac OS X and Cygwin, matching
with prefix strings ignores a case (0.7.7).
However, comparison is limited to one-byte locales.
Regular expressions can contain captures (0.7.40) that can later be used in
other directives.
If the longest matching prefix location has the
.Qq ^~
modifier then regular expressions are not checked.
Also, using the
.Cm =
modifier 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 / request happens frequently, defining
.Qq location=/
will speed up the processing of these requests, as search terminates right after
the first comparison.
Such a location cannot obviously contain nested locations.
In versions from 0.7.1 to 0.8.41, if a request matched the prefix location
without the
.Qq =
and
.Qq ^~
modifiers, the search also terminated and regular expressions were not checked.
Let's illustrate the above by an example:
.Bd -literal -offset indent
location = / {
[ configuration A ]
}
location / {
[ configuration B ]
}
location /documents/ {
[ configuration C ]
}
location ^~ /images/ {
[ configuration D ]
}
location ~* \\.(gif |jpg |jpeg)$ {
[ configuration E ]
}
.Ed
.Pp
The
.Qq /
request will match configuration A, the
.Qq /index.html
request will match configuration B, the
.Qq /documents/document.html
request will match configuration C, the
.Qq /images/1.gif
request will match configuration D, and the
.Qq /documents/1.jpg
request will match configuration E.
The
.Cm @
prefix defines a named location.
Such a location is not used for a regular request processing, but instead used
for request redirection.
They cannot be nested, and cannot contain nested locations.
If a location is defined by a prefix string that ends with the slash character,
and requests are processed by one of
.Ic proxy_pass ,
.Ic fastcgi_pass ,
.Ic scgi_pass ,
.Ic uwsgi_pass ,
or
.Ic memcached_pass ,
then in response to a request with URI equal to this string, but without the
trailing slash, a permanent redirect with the code 301 will be returned to the
requested URI with the slash appended.
If this is not desired, an exact match of the URI and location could be defined
like this:
.Bd -literal -offset indent
location /user/ {
proxy_pass http://user.example.com;
}
location = /user {
proxy_pass http://login.example.com;
}
.Ed
.It Ic log_not_found Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables logging of errors about not found files into
.Ic error_log .
.It Ic log_subrequest Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables logging of subrequests into
.Ic access_log .
.It Ic max_ranges Ar number
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Limits the maximum allowed number of ranges in byte-range requests.
Requests that exceed the limit are processed as if there were no byte ranges
specified.
By default, the number of ranges is not limited.
The zero value disables the byte-range support completely.
.It Ic merge_slashes Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server
.El
.Pp
Enables or disables compression of two or more adjacent slashes in a URI into a
single slash.
Note that compression is essential for the correct matching of prefix string and
regular expression locations.
Without it, the
.Qq //scripts/one.php
request would not match
.Bd -literal -offset indent
location /scripts/ {
...
}
.Ed
.Pp
and might be processed as a static file.
So it gets converted to
.Qq /scripts/one.php .
Turning the compression
.Cm off
can become necessary if a URI contains base64-encoded names, since base64 uses
the
.Qq /
character internally.
However, for security considerations, it is better to avoid turning the
compression off.
A directive can be specified on the
.Ic server
level in the default server.
In this case, its value will apply to all virtual servers listening on the same
address and port.
.It Ic msie_padding Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables adding comments to responses for MSIE clients with status
greater than 400 to increase the response size to 512 bytes.
.It Ic msie_refresh Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables issuing refreshes instead of redirects for MSIE clients.
.It Ic open_file_cache Cm off
.It Ic open_file_cache Cm max Ns = Ns Ar N Oo Cm inactive Ns = Ns Ar time Oc
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Configures a cache that can store:
.Bl -bullet
.It
open file descriptors, their sizes and modification times;
.It
information on existence of directories;
.It
file lookup errors, such as file not found, no read permission, and so on.
Caching of errors should be enabled separately by the
.Ic open_file_cache_errors
directive.
.El
.Pp
The directive has the following parameters:
.Bl -tag -width Ds
.It Cm max
sets the maximum number of elements in the cache; on cache overflow the least
recently used (LRU) elements are removed;
.It Cm inactive
defines a time after which an element is removed from the cache if it has not
been accessed during this time; by default, it is 60 seconds;
.It Cm off
disables the cache.
.El
.Pp
Example:
.Bd -literal -offset indent
open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
.Ed
.It Ic open_file_cache_errors Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables caching of file lookup errors by
.Ic open_file_cache .
.It Ic open_file_cache_min_uses Ar number
.Bl -tag -width Ds -compact
.It default: 1
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the minimum
.Ar number
of file accesses during the period configured by the
.Cm inactive
parameter of the
.Ic open_file_cache
directive, required for a file descriptor to remain open in the cache.
.It Ic open_file_cache_valid Ar time
.Bl -tag -width Ds -compact
.It default: 60s
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets a time after which
.Ic open_file_cache
elements should be validated.
.It Ic optimize_server_names Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server
.El
.Pp
This directive is obsolete.
The
.Ic server_name_in_redirect
directive should be used instead.
.It Ic port_in_redirect Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables specifying the port in redirects issued by nginx.
The use of the primary server name in redirects is controlled by the
.Ic server_name_in_redirect
directive.
.It Ic postpone_output Ar size
.Bl -tag -width Ds -compact
.It default: 1460
.It context: Ic http , Ic server , Ic location
.El
.Pp
If possible, the transmission of client data will be postponed until nginx has
at least
.Ar size
bytes of data to send.
The zero value disables postponing data transmission.
.It Ic read_ahead Ar size
.Bl -tag -width Ds -compact
.It default: 0
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the amount of pre-reading for the kernel when working with file.
On Linux, the
.Fn posix_fadvise 0 0 0 POSIX_FADV_SEQUENTIAL
system call is used, and so the
.Ar size
parameter is ignored.
On FreeBSD, the
.Fn fcntl O_READAHEAD size
system call, supported since FreeBSD 9.0-CURRENT, is used.
FreeBSD 7 has to be patched.
.It Ic recursive_error_pages Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables doing several redirects using the
.Ic error_page
directive.
The number of such redirects is
.Ic internal
limited .
.It Ic request_pool_size Ar size
.Bl -tag -width Ds -compact
.It default: 4k
.It context: Ic http , Ic server
.El
.Pp
Allows accurate tuning of per-request memory allocations.
This directive has minimal impact on performance and should not generally be
used.
.It Ic reset_timedout_connection Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables resetting timed out connections.
The reset is performed as follows.
Before closing a socket, the
.Dv SO_LINGER
option is set on it with a timeout value of 0.
When the socket is closed, TCP RST is sent to the client, and all memory
occupied by this socket is released.
This helps avoid keeping an already closed socket with filled buffers in a
FIN_WAIT1 state for a long time.
It should be noted that timed out keep-alive connections are closed normally.
.It Ic resolver Ar address No ... Oo Cm valid Ns = Ns Ar time Oc
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Configures name servers used to resolve names of upstream servers into
addresses, for example:
.Bd -literal -offset indent
resolver 127.0.0.1 [::1]:5353;
.Ed
.Pp
An
.Ar address
can be specified as a domain name or IP address, and an optional port
(1.3.1, 1.2.2).
If port is not specified, the port 53 is used.
Name servers are queried in a round-robin fashion.
Before version 1.1.7, only a single name server could be configured.
Specifying name servers using IPv6 addresses is supported starting from versions
1.3.1 and 1.2.2.By default, nginx caches answers using the TTL value of a
response.
An optional
.Cm valid
parameter allows overriding it:
.Bd -literal -offset indent
resolver 127.0.0.1 [::1]:5353 valid=30s;
.Ed
.Pp
Before version 1.1.9, tuning of caching time was not possible, and nginx always
cached answers for the duration of 5 minutes.
.It Ic resolver_timeout Ar time
.Bl -tag -width Ds -compact
.It default: 30s
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets a timeout for name resolution, for example:
.Bd -literal -offset indent
resolver_timeout 5s;
.Ed
.It Ic root Ar path
.Bl -tag -width Ds -compact
.It default: Pa html
.It context: Ic http , Ic server , Ic location , Ic if in location
.El
.Pp
Sets the root directory for requests.
For example, with the following configuration
.Bd -literal -offset indent
location /i/ {
root /data/w3;
}
.Ed
.Pp
The
.Pa /data/w3/i/top.gif
file will be sent in response to the
.Qq /i/top.gif
request.
The
.Ar path
value can contain variables, except
.Va $document_root
and
.Va $realpath_root .
A path to the file is constructed by merely adding a URI to the value of the
.Ic root
directive.
If a URI has to be modified, the
.Ic alias
directive should be used.
.It Ic satisfy Cm all | Cm any
.Bl -tag -width Ds -compact
.It default: all
.It context: Ic http , Ic server , Ic location
.El
.Pp
Allows access if all
.Pq Ic all
or at least one
.Pq Ic any
of the
.Sx Module ngx_http_access_module ,
.Sx Module ngx_http_auth_basic_module
or
.Sx Module ngx_http_auth_request_module
modules allow access.
Example:
.Bd -literal -offset indent
location / {
satisfy any;
allow 192.168.1.0/32;
deny all;
auth_basic "closed site";
auth_basic_user_file conf/htpasswd;
}
.Ed
.It Ic satisfy_any Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
This directive has been replaced by the
.Cm any
parameter of the
.Ic satisfy
directive.
.It Ic send_lowat Ar size
.Bl -tag -width Ds -compact
.It default: 0
.It context: Ic http , Ic server , Ic location
.El
.Pp
If the directive is set to a non-zero value, nginx will try to minimize the
number of send operations on client sockets by using either
.Dv NOTE_LOWAT
flag of the
.Cm kqueue
method or the
.Dv SO_SNDLOWAT
socket option.
In both cases the specified
.Ar size
is used.
This directive is ignored on Linux, Solaris, and Windows.
.It Ic send_timeout Ar time
.Bl -tag -width Ds -compact
.It default: 60s
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets a timeout for transmitting a response to the client.
A timeout is set only 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.
.It Ic sendfile Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location , Ic if in location
.El
.Pp
Enables or disables the use of
.Fn sendfile .
.It Ic sendfile_max_chunk Ar size
.Bl -tag -width Ds -compact
.It default: 0
.It context: Ic http , Ic server , Ic location
.El
.Pp
When set to a non-zero value, limits the amount of data that can be transferred
in a single
.Fn sendfile
call.
Without the limit, one fast connection may seize the worker process entirely.
.It Ic server Brq No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
Sets configuration for a virtual server.
There is no clear separation between IP-based (based on the IP address) and
name-based (based on the Host request header field) virtual servers.
Instead, the
.Ic listen
directives describe all addresses and ports that should accept connections for
the server, and the
.Ic server_name
directive lists all server names.
.It Ic server_name Ar name No ...
.Bl -tag -width Ds -compact
.It default: Qq
.It context: Ic server
.El
.Pp
Sets names of a virtual server, for example:
.Bd -literal -offset indent
server {
server_name example.com www.example.com;
}
.Ed
.Pp
The first name becomes the primary server name.
Server names can include an asterisk
.Pq Ic *
replacing the first or last part of a name:
.Bd -literal -offset indent
server {
server_name example.com *.example.com www.example.*;
}
.Ed
.Pp
Such names are called wildcard names.
The first two of the names mentioned above can be combined in one:
.Bd -literal -offset indent
server {
server_name .example.com;
}
.Ed
.Pp
It is also possible to use regular expressions in server names, preceeding the
name with a tilde
.Pq Ic ~ :
.Bd -literal -offset indent
server {
server_name www.example.com ~^www\\d+\\.example\\.com$;
}
.Ed
.Pp
Regular expressions can contain captures (0.7.40) that can later be used in
other directives:
.Bd -literal -offset indent
server {
server_name ~^(www\\.)?(.+)$;
location / {
root /sites/$2;
}
}
server {
server_name _;
location / {
root /sites/default;
}
}
.Ed
.Pp
Named captures in regular expressions create variables (0.8.25) that can later
be used in other directives:
.Bd -literal -offset indent
server {
server_name ~^(www\\.)?(?<domain>.+)$;
location / {
root /sites/$domain;
}
}
server {
server_name _;
location / {
root /sites/default;
}
}
.Ed
.Pp
If the directive's parameter is set to
.Va $hostname
(0.9.4), the machine's hostname is inserted.
It is also possible to specify an empty server name (0.7.11):
.Bd -literal -offset indent
server {
server_name www.example.com "";
}
.Ed
.Pp
It allows this server to process requests without the Host header field -
instead of the default server - for the given
.Ar address Ns : Ns Ar port
pair.
This is the default setting.
Before 0.8.48, the machine's hostname was used by default.
During searching for a virtual server by name, if the name matches more than one
of the specified variants, (e.g. both a wildcard name and regular expression
match), the first matching variant will be chosen, in the following order of
priority:
.Bl -bullet
.It
the exact name
.It
the longest wildcard name starting with an asterisk, e.g.
.Ic *.example.com
.It
the longest wildcard name ending with an asterisk, e.g.
.Cm mail.*
.It
the first matching regular expression (in order of appearance in the
configuration file)
.El
Detailed description of server names is provided in a separate document.
.It Ic server_name_in_redirect Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables the use of the primary server name, specified by the
.Ic server_name
directive, in redirects issued by nginx.
When the use of the primary server name is disabled, the name from the Host
request header field is used.
If this field is not present, the IP address of the server is used.
The use of a port in redirects is controlled by the
.Ic port_in_redirect
directive.
.It Ic server_names_hash_bucket_size Ar size
.Bl -tag -width Ds -compact
.It default: 32 | 64 | 128
.It context: Ic http
.El
.Pp
Sets the bucket size for the server names hash tables.
The default value depends on the size of the processor's cache line.
The details of setting up hash tables are provided in a separate document.
.It Ic server_names_hash_max_size Ar size
.Bl -tag -width Ds -compact
.It default: 512
.It context: Ic http
.El
.Pp
Sets the maximum
.Ar size
of the server names hash tables.
The details of setting up hash tables are provided in a separate document.
.It Ic server_tokens Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables emitting nginx version in error messages and in the Server
response header field.
.It Ic tcp_nodelay Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables the use of the
.Dv TCP_NODELAY
option.
The option is enabled only when a connection is transitioned into the keep-alive
state.
.It Ic tcp_nopush Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables the use of the
.Dv TCP_NOPUSH
socket option on FreeBSD or the
.Dv TCP_CORK
socket option on Linux.
The options are enabled only when
.Ic sendfile
is used.
Enabling the option allows
.Bl -bullet
.It
sending the response header and the beginning of a file in one packet, on Linux
and FreeBSD 4.*;
.It
sending a file in full packets.
.El
.It Ic try_files Ar file No ... Ar uri
.It Ic try_files Ar file No ... = Ns Ar code
.Bl -tag -width Ds -compact
.It default:
.It context: Ic server , Ic location
.El
.Pp
Checks the existence of files in the specified order and uses the first found
file for request processing; the processing is performed in the current context.
The path to a file is constructed from the
.Ar file
parameter according to the
.Ic root
and
.Ic alias
directives.
It is possible to check directory's existence by specifying a slash at the end
of a name, e.g.
.Qq $uri/ .
If none of the files were found, an internal redirect to the
.Ar uri
specified in the last parameter is made.
For example:
.Bd -literal -offset indent
location /images/ {
try_files $uri /images/default.gif;
}
location = /images/default.gif {
expires 30s;
}
.Ed
.Pp
The last parameter can also point to a named location, as shown in examples
below.
Starting from version 0.7.51, the last parameter can also be a
.Ar code :
.Bd -literal -offset indent
location / {
try_files $uri $uri/index.html $uri.html =404;
}
.Ed
.Pp
Example in proxying Mongrel:
.Bd -literal -offset indent
location / {
try_files /system/maintenance.html
$uri $uri/index.html $uri.html
@mongrel;
}
location @mongrel {
proxy_pass http://mongrel;
}
.Ed
.Pp
Example for Drupal/FastCGI:
.Bd -literal -offset indent
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&$args;
... other fastcgi_param's
}
.Ed
.Pp
In the following example,
.Bd -literal -offset indent
location / {
try_files $uri $uri/ @drupal;
}
.Ed
.Pp
the
.Ic try_files
directive is equivalent to
.Bd -literal -offset indent
location / {
error_page 404 = @drupal;
log_not_found off;
}
.Ed
.Pp
And here,
.Bd -literal -offset indent
location ~ \\.php$ {
try_files $uri @drupal;
fastcgi_pass ...;
fastcgi_param SCRIPT_FILENAME /path/to$fastcgi_script_name;
...
}
.Ed
.Pp
.Ic try_files
checks the existence of the PHP file before passing the request to the FastCGI
server.
Example for Wordpress and Joomla:
.Bd -literal -offset indent
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
}
.Ed
.It Ic types Brq No ...
.Bl -tag -width Ds -compact
.It default:
.Bd -literal -offset indent
text/html html;
image/gif gif;
image/jpeg jpg;
.Ed
.It context: Ic http , Ic server , Ic location
.El
.Pp
Maps file name extensions to MIME types of responses.
Extensions are case-insensitive.
Several extensions can be mapped to one type, for example:
.Bd -literal -offset indent
types {
application/octet-stream bin exe dll;
application/octet-stream deb;
application/octet-stream dmg;
}
.Ed
.Pp
A sufficiently full mapping table is distributed with nginx in the
.Pa conf/mime.types
file.
To make a particular location emit the
application/octet-stream
MIME type for all requests, the following configuration can be used:
.Bd -literal -offset indent
location /download/ {
types { }
default_type application/octet-stream;
}
.Ed
.It Ic types_hash_bucket_size Ar size
.Bl -tag -width Ds -compact
.It default: 32 | 64 | 128
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the bucket size for the types hash tables.
The default value depends on the size of the processor's cache line.
The details of setting up hash tables are provided in a separate document.
.It Ic types_hash_max_size Ar size
.Bl -tag -width Ds -compact
.It default: 1024
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the maximum
.Ar size
of the types hash tables.
The details of setting up hash tables are provided in a separate document.
.It Ic underscores_in_headers Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server
.El
.Pp
Enables or disables the use of underscores in client request header fields.
When the use of underscores is disabled, request header fields whose names
contain underscores are marked as invalid and become subject to the
.Ic ignore_invalid_headers
directive.
A directive can be specified on the
.Ic server
level in a default server.
In this case, its value will apply to all virtual servers listening on the same
address and port.
.It Ic variables_hash_bucket_size Ar size
.Bl -tag -width Ds -compact
.It default: 64
.It context: Ic http
.El
.Pp
Sets the bucket size for the variables hash table.
The details of setting up hash tables are provided in a separate document.
.It Ic variables_hash_max_size Ar size
.Bl -tag -width Ds -compact
.It default: 512
.It context: Ic http
.El
.Pp
Sets the maximum
.Ar size
of the variables hash table.
The details of setting up hash tables are provided in a separate document.
.El
.Ss Embedded Variables
The
.Sx Module ngx_http_core_module
module supports embedded variables with names matching the Apache Server
variables.
First of all, these are variables representing client request header fields,
such as
.Va $http_user_agent ,
.Va $http_cookie ,
and so on.
Also there are other variables:
.Bl -tag -width Ds
.It Va $arg_ Ns Ar name
argument
.Ar name
in the request line
.It Va $args
arguments in the request line
.It Va $binary_remote_addr
client address in a binary form, value's length is always 4 bytes
.It Va $body_bytes_sent
number of bytes sent to a client, not counting the response header; this
variable is compatible with the
.Qq %B
parameter of the mod_log_config Apache module
.It Va $bytes_sent
number of bytes sent to a client (1.3.8, 1.2.5)
.It Va $connection
connection serial number (1.3.8, 1.2.5)
.It Va $connection_requests
current number of requests made through a connection (1.3.8, 1.2.5)
.It Va $content_length
Content-Length request header field
.It Va $content_type
Content-Type request header field
.It Va $cookie_ Ns Ar name
the
.Ar name
cookie
.It Va $document_root
.Ic root
or
.Ic alias
directive's value for the current request
.It Va $document_uri
same as
.Va $uri
.It Va $host
in this order of precedence: host name from the request line, or host name from
the Host request header field, or the server name matching a request
.It Va $hostname
host name
.It Va $http_ Ns Ar name
arbitrary request header field; the last part of a variable name is the field
name converted to lower case with dashes replaced by underscores
.It Va $https
.Qq on
if connection operates in SSL mode, or an empty string otherwise
.It Va $is_args
.Qo ? Qc
if a request line has arguments, or an empty string otherwise
.It Va $limit_rate
setting this variable enables response rate limiting; see
.Ic limit_rate
.It Va $msec
current time in seconds with the milliseconds resolution (1.3.9, 1.2.6)
.It Va $nginx_version
nginx version
.It Va $pid
PID of the worker process
.It Va $pipe
.Qq p
if request was pipelined,
.Qo . Qc
otherwise (1.3.12, 1.2.7)
.It Va $query_string
same as
.Va $args
.It Va $realpath_root
an absolute pathname corresponding to the
.Ic root
or
.Ic alias
directive's value for the current request, with all symbolic links resolved to
real paths
.It Va $remote_addr
client address
.It Va $remote_port
client port
.It Va $remote_user
user name supplied with the Basic authentication
.It Va $request
full original request line
.It Va $request_body
request body
.Pp
The variable's value is made available in locations processed by the
.Ic proxy_pass
and
.Ic fastcgi_pass
directives.
.It Va $request_body_file
name of a temporary file with the request body
.Pp
At the end of processing, the file needs to be removed.
To always write the request body to a file,
.Ic client_body_in_file_only
needs to be enabled.
When the name of a temporary file is passed in a proxied request or in a request
to a FastCGI server, passing the request body should be disabled by the
.Ic proxy_pass_request_body Cm off
and
.Ic fastcgi_pass_request_body Cm off
directives, respectively.
.It Va $request_completion
.Qq OK
if a request has completed, or an empty string otherwise
.It Va $request_filename
file path for the current request, based on the
.Ic root
or
.Ic alias
directives, and the request URI
.It Va $request_length
request length (including request line, header, and request body) (1.3.12,
1.2.7)
.It Va $request_method
request method, usually
.Cm GET
or
.Cm POST
.It Va $request_time
request processing time in seconds with a milliseconds resolution (1.3.9,
1.2.6); time elapsed since the first bytes were read from the client
.It Va $request_uri
full original request URI (with arguments)
.It Va $scheme
request scheme,
.Qq http
or
.Qq https
.It Va $sent_http_ Ns Ar name
arbitrary response header field; the last part of a variable name is the field
name converted to lower case with dashes replaced by underscores
.It Va $server_addr
an address of the server which accepted a request
.Pp
Computing a value of this variable usually requires one system call.
To avoid a system call, the
.Ic listen
directives must specify addresses and use the
.Ic bind
parameter.
.It Va $server_name
name of the server which accepted a request
.It Va $server_port
port of the server which accepted a request
.It Va $server_protocol
request protocol, usually
.Qq HTTP/1.0
or
.Qq HTTP/1.1
.It Va $status
response status (1.3.2, 1.2.2)
.It Va $tcpinfo_rtt ,
.Va $tcpinfo_rttvar ,
.Va $tcpinfo_snd_cwnd ,
.Va $tcpinfo_rcv_space
information about the client TCP connection; available on systems that support
the
.Dv TCP_INFO
socket option
.It Va $time_iso8601
local time in the ISO 8601 standard format (1.3.12, 1.2.7)
.It Va $time_local
local time in the Common Log Format (1.3.12, 1.2.7)
.It Va $uri
current URI in request, normalized
.Pp
The value of
.Va $uri
may change during request processing, e.g. when doing internal redirects, or
when using index files.
.El
.Ss Module ngx_http_access_module
.Bl -tag -width Ds
.It Ic allow Ar address | Ar CIDR | Cm unix: | Cm all
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location , Ic limit_except
.El
.Pp
Allows access for the specified network or address.
If the special value
.Cm unix:
is specified (1.5.1), allows access for all UNIX-domain sockets.
.It Ic deny Ar address | Ar CIDR | Cm unix: | Cm all
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location , Ic limit_except
.El
.Pp
Denies access for the specified network or address.
If the special value
.Cm unix:
is specified (1.5.1), denies access for all UNIX-domain sockets.
.El
.Ss Module ngx_http_addition_module
.Em This module is not enabled on OpenBSD.
.Bl -tag -width Ds
.It Ic add_before_body Ar uri
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Adds the text returned as a result of processing a given subrequest before the
response body.
An empty string
.Pq Ic ""
as a parameter cancels addition inherited from the previous configuration
level.
.It Ic add_after_body Ar uri
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Adds the text returned as a result of processing a given subrequest after the
response body.
An empty string
.Pq Ic ""
as a parameter cancels addition inherited from the previous configuration
level.
.It Ic addition_types Ar mime-type No ...
.Bl -tag -width Ds -compact
.It default: text/html
.It context: Ic http , Ic server , Ic location
.El
.Pp
Allows adding text in responses with the specified MIME types, in addition to
.Qq text/html .
The special value
.Qq *
matches any MIME type (0.8.29).
.El
.Ss Module ngx_http_auth_basic_module
.Bl -tag -width Ds
.It Ic auth_basic Ar string | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location , Ic limit_except
.El
.Pp
Enables validation of user name and password using the HTTP Basic Authentication
protocol.
The specified parameter is used as a realm.
Parameter value can contain variables (1.3.10, 1.2.7).
The special value
.Cm off
allows cancelling the effect of the
.Ic auth_basic
directive inherited from the previous configuration level.
.It Ic auth_basic_user_file Ar file
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location , Ic limit_except
.El
.Pp
Specifies a file that keeps user names and passwords, in the following format:
.Bd -literal -offset indent
# comment
name1:password1
name2:password2:comment
name3:password3
.Ed
.Pp
The following password types are supported:
.Bl -bullet
.It
encrypted with the
.Fn crypt
function; can be generated using the
.Ic htpasswd
utility from the Apache HTTP Server distribution or the
.Ic openssl passwd
command;
.It
hashed with the Apache variant of the MD5-based password algorithm (apr1); can
be generated with the same tools;
.It
specified by the
.Brq Ar scheme
data syntax (1.0.3+) as described in RFC 2307; currently implemented schemes
include
.Cm PLAIN
(an example one, should not be used),
.Cm SHA
(1.3.13) (plain SHA-1 hashing, should not be used) and
.Cm SSHA
(salted SHA-1 hashing, used by some software packages, notably OpenLDAP and
Dovecot).
Support for
.Cm SHA
scheme was added only to aid in migration from other web servers.
It should not be used for new passwords, since unsalted SHA-1 hashing that it
employs is vulnerable to
rainbow table
attacks.
.El
.El
.Ss Module ngx_http_auth_request_module
.Em This module is not enabled on OpenBSD.
.Bl -tag -width Ds
.It Ic auth_request Ar uri | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables authorization based on the result of a subrequest and sets the URI to
which the subrequest will be sent.
.It Ic auth_request_set Ar variable Ar value
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the request
.Ar variable
to the given
.Ar value
after the authorization request completes.
The value may contain variables from the authorization request, such as
.Va $upstream_http_* .
.El
.Ss Module ngx_http_autoindex_module
.Bl -tag -width Ds
.It Ic autoindex Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables the directory listing output.
.It Ic autoindex_exact_size Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server , Ic location
.El
.Pp
Specifies whether exact file sizes should be output in the directory listing, or
rather rounded to kilobytes, megabytes, and gigabytes.
.It Ic autoindex_localtime Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Specifies whether times in the directory listing should be output in the local
time zone or UTC.
.El
.Ss Module ngx_http_browser_module
.Bl -tag -width Ds
.It Ic ancient_browser Ar string No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
If any of the specified substrings is found in the User-Agent request header
field, the browser will be considered ancient.
The special string
.Cm netscape4
corresponds to the regular expression
.Qq ^Mozilla Ns / Ns Oo 1-4 Oc .
.It Ic ancient_browser_value Ar string
.Bl -tag -width Ds -compact
.It default: 1
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets a value for the
.Va $ancient_browser
variables.
.It Ic modern_browser Ar browser Ar version
.It Ic modern_browser Cm unlisted
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Specifies a version starting from which a browser is considered modern.
A browser can be any one of the following:
.Cm msie ,
.Cm gecko
(browsers based on Mozilla),
.Cm opera ,
.Cm safari ,
or
.Cm konqueror .
Versions can be specified in the following formats: X, X.X, X.X.X, or X.X.X.X.
The maximum values for each of the format are 4000, 4000.99, 4000.99.99, and
4000.99.99.99, respectively.
The special value
.Cm unlisted
specifies to consider a browser as modern if it was not listed by the
.Ic modern_browser
and
.Ic ancient_browser
directives.
Otherwise such a browser is considered ancient.
If a request does not provide the User-Agent field in the header, the browser is
treated as not being listed.
.It Ic modern_browser_value Ar string
.Bl -tag -width Ds -compact
.It default: 1
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets a value for the
.Va $modern_browser
variables.
.El
.Ss Module ngx_http_charset_module
.Bl -tag -width Ds
.It Ic charset Ar charset | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location , Ic if in location
.El
.Pp
Adds the specified
.Ar charset
to the Content-Type response header field.
If this charset is different from the charset specified in the
.Ic source_charset
directive, a conversion is performed.
The parameter
.Cm off
cancels the addition of charset to the Content-Type response header field.
A charset can be defined with a variable:
.Bd -literal -offset indent
charset $charset;
.Ed
.Pp
In such a case, all possible values of a variable need to be present in the
configuration at least once in the form of the
.Ic charset_map ,
.Ic charset ,
or
.Ic source_charset
directives.
For
.Cm utf-8 ,
.Cm windows-1251 ,
and
.Cm koi8-r
charsets, it is sufficient to include the files
.Pa conf/koi-win ,
.Pa conf/koi-utf ,
and
.Pa conf/win-utf
into configuration.
For other charsets, simply making a fictitious conversion table works, for
example:
.Bd -literal -offset indent
charset_map iso-8859-5 _ { }
.Ed
.Pp
In addition, a charset can be set in the X-Accel-Charset response header field.
This capability can be disabled using the
.Ic proxy_ignore_headers
and
.Ic fastcgi_ignore_headers
directives.
.It Ic charset_map Ar charset1 Ar charset2 Brq No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
Describes the conversion table from one charset to another.
A reverse conversion table is built using the same data.
Character codes are given in hexadecimal.
Missing characters in the range 80-FF are replaced with
.Qq ? .
When converting from UTF-8, characters missing in a one-byte charset are
replaced with
.Qq &#XXXX; .
Example:
.Bd -literal -offset indent
charset_map koi8-r windows-1251 {
C0 FE ; # small yu
C1 E0 ; # small a
C2 E1 ; # small b
C3 F6 ; # small ts
...
}
.Ed
.Pp
When describing a conversion table to UTF-8, codes for the UTF-8 charset should
be given in the second column, for example:
.Bd -literal -offset indent
charset_map koi8-r utf-8 {
C0 D18E ; # small yu
C1 D0B0 ; # small a
C2 D0B1 ; # small b
C3 D186 ; # small ts
...
}
.Ed
.Pp
Full conversion tables from
.Cm koi8-r
to
.Cm windows-1251 ,
and from
.Cm koi8-r
and
.Cm windows-1251
to
.Cm utf-8
are provided in the distribution files
.Pa conf/koi-win ,
.Pa conf/koi-utf ,
and
.Pa conf/win-utf .
.It Ic charset_types Ar mime-type No ...
.Bl -tag -width Ds -compact
.It default: text/html text/xml text/plain text/vnd.wap.wml
application/javascript application/rss+xml
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables module processing in responses with the specified MIME types in addition
to
.Ar text/html.
The special value
.Qq *
matches any MIME type (0.8.29).
Until version 1.5.4,
application/x-javascript
was used as the default MIME type instead of
application/javascript .
.It Ic override_charset Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location , Ic if in location
.El
.Pp
Determines whether a conversion should be performed for answers received from a
proxied or FastCGI server when the answers already carry a charset in the
Content-Type response header field.
If conversion is enabled, a charset specified in the received response is used
as a source charset.
It should be noted that if a response is received in a subrequest then the
conversion from the response charset to the main request charset is always
performed, regardless of the
.Ic override_charset
directive setting.
.It Ic source_charset Ar charset
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location , Ic if in location
.El
.Pp
Defines the source charset of a response.
If this charset is different from the charset specified in the
.Ic charset
directive, a conversion is performed.
.El
.Ss Module ngx_http_dav_module
.Em This module is not enabled on OpenBSD.
.Bl -tag -width Ds
.It Ic dav_access Ar users Ns : Ns Ar permissions No ...
.Bl -tag -width Ds -compact
.It default: user:rw
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets access permissions for newly created files and directories, e.g.:
.Bd -literal -offset indent
dav_access user:rw group:rw all:r;
.Ed
.Pp
If any
.Ar group
or
.Cm all
access permissions are specified then
.Ar user
permissions may be omitted:
.Bd -literal -offset indent
dav_access group:rw all:r;
.Ed
.It Ic dav_methods Cm off | Ar method No ...
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Allows the specified HTTP and WebDAV methods.
The parameter
.Cm off
denies all methods processed by this module.
The following methods are supported:
.Cm PUT ,
.Cm DELETE ,
.Cm MKCOL ,
.Cm COPY ,
and
.Cm MOVE .
A file uploaded with the
.Cm PUT
method is first written to a temporary file, and then the file is renamed.
Starting from version 0.8.9, temporary files and the persistent store can be put
on different file systems.
However, be aware that in this case a file is copied across two file systems
instead of the cheap renaming operation.
It is thus recommended that for any given location both saved files and a
directory holding temporary files, set by the
.Ic client_body_temp_path
directive, are put on the same file system.
When creating a file with the
.Cm PUT
method, it is possible to specify the modification date by passing it in the
Date header field.
.It Ic create_full_put_path Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
The WebDAV specification only allows creating files in already existing
directories.
This directive allows creating all needed intermediate directories.
.It Ic min_delete_depth Ar number
.Bl -tag -width Ds -compact
.It default: 0
.It context: Ic http , Ic server , Ic location
.El
.Pp
Allows the DELETE method to remove files provided that the number of elements in
a request path is not less than the specified number.
For example, the directive
.Bd -literal -offset indent
min_delete_depth 4;
.Ed
.Pp
allows removing files on requests
.Bd -literal -offset indent
/users/00/00/name
/users/00/00/name/pic.jpg
/users/00/00/page.html
.Ed
.Pp
and denies the removal of
.Bd -literal -offset indent
/users/00/00
.Ed
.El
.Ss Module ngx_http_empty_gif_module
.Bl -tag -width Ds
.It Ic empty_gif
.Bl -tag -width Ds -compact
.It default:
.It context: Ic location
.El
.Pp
Turns on module processing in a surrounding location.
.El
.Ss Module ngx_http_f4f_module
.Em This module is only available in the commercial version of nginx.
.Bl -tag -width Ds
.It Ic f4f
.Bl -tag -width Ds -compact
.It default:
.It context: Ic location
.El
.Pp
Turns on module processing in the surrounding location.
.It Ic f4f_buffer_size Ar size
.Bl -tag -width Ds -compact
.It default: 512k
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the size of a memory buffer used for reading the
.Pa .f4x
index file.
.El
.Ss Module ngx_http_fastcgi_module
.Bl -tag -width Ds
.It Ic fastcgi_bind Ar address | Cm off
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Makes outgoing connections to a FastCGI server originate from the specified
local IP
.Ar address.
Parameter value can contain variables (1.3.12).
The special value
.Cm off
(1.3.12) cancels the effect of the
.Ic fastcgi_bind
directive inherited from the previous configuration level, which allows the
system to auto-assign the local IP address.
.It Ic fastcgi_buffer_size Ar size
.Bl -tag -width Ds -compact
.It default: 4k | 8k
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the
.Ar size
of the buffer used for reading the first part of a response received from the
FastCGI server.
This part usually contains a small response header.
By default, the buffer size is equal to the size of one buffer set by the
.Ic fastcgi_buffers
directive.
It can be made smaller however.
.It Ic fastcgi_buffering Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables buffering of responses from the FastCGI server.
When buffering is enabled,
nginx receives a response from the FastCGI server as
soon as possible, saving it into the buffers set by the
.Ic fastcgi_buffer_size
and
.Ic fastcgi_buffers
directives.
If the whole response does not fit into memory, a part of it can be saved to a
.Ic fastcgi_temp_path
temporary file
on the disk.
Writing to temporary files is controlled by the
.Ic fastcgi_max_temp_file_size
and
.Ic fastcgi_temp_file_write_size
directives.
When buffering is disabled, a response is passed to a client synchronously,
immediately as it is received.
nginx will not try to read the whole response from the FastCGI server.
The maximum size of the data that nginx can receive from the server at a time is
set by the
.Ic fastcgi_buffer_size
directive.
Buffering can also be enabled or disabled by passing
.Cm yes
or
.Cm no
in the X-Accel-Buffering response header field.
This capability can be disabled using the
.Ic fastcgi_ignore_headers
directive.
.It Ic fastcgi_buffers Ar number Ar size
.Bl -tag -width Ds -compact
.It default: 8 4k | 8k
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the
.Ar number
and
.Ar size
of buffers used for reading a response from the FastCGI server, for a single
connection.
By default, the buffer size is equal to one memory page.
This is either 4K or 8K, depending on a platform.
.It Ic fastcgi_busy_buffers_size Ar size
.Bl -tag -width Ds -compact
.It default: 8k | 16k
.It context: Ic http , Ic server , Ic location
.El
.Pp
When
.Ic fastcgi_buffering
buffering
of responses from the FastCGI server is enabled, limits the total
.Ar size
of buffers that can be busy sending a response to the client while the response
is not yet fully read.
In the mean time, the rest of the buffers can be used for reading a response
and, if needed, buffering part of a response to a temporary file.
By default,
.Ar size
is limited by the size of two buffers set by the
.Ic fastcgi_buffer_size
and
.Ic fastcgi_buffers
directives.
.It Ic fastcgi_cache Ar zone | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines a shared memory zone used for caching.
The same zone can be used in several places.
The
.Cm off
parameter disables caching inherited from the previous configuration level.
.It Ic fastcgi_cache_bypass Ar string No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines conditions under which the response will not be taken from a cache.
If at least one value of the
.Ar string
parameters is not empty and is not equal to 0 then the response will not be
taken from the cache:
.Bd -literal -offset indent
fastcgi_cache_bypass $cookie_nocache $arg_nocache$arg_comment;
fastcgi_cache_bypass $http_pragma $http_authorization;
.Ed
.Pp
Can be used along with the
.Ic fastcgi_no_cache
directive.
.It Ic fastcgi_cache_key Ar string
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines a key for caching, for example
.Bd -literal -offset indent
fastcgi_cache_key localhost:9000$request_uri;
.Ed
.It Ic fastcgi_cache_lock Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
When enabled, only one request at a time will be allowed to populate a new cache
element identified according to the
.Ic fastcgi_cache_key
directive by passing a request to a FastCGI server.
Other requests of the same cache element will either wait for a response to
appear in the cache or the cache lock for this element to be released, up to the
time set by the
.Ic fastcgi_cache_lock_timeout
directive.
.It Ic fastcgi_cache_lock_timeout Ar time
.Bl -tag -width Ds -compact
.It default: 5s
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets a timeout for
.Ic fastcgi_cache_lock .
.It Ic fastcgi_cache_methods Cm GET | Cm HEAD | Cm POST No ...
.Bl -tag -width Ds -compact
.It default: Cm GET Cm HEAD
.It context: Ic http , Ic server , Ic location
.El
.Pp
If the client request method is listed in this directive then the response will
be cached.
.Cm GET
and
.Cm HEAD
methods are always added to the list, though it is recommended to specify them
explicitly.
See also the
.Ic fastcgi_no_cache
directive.
.It Ic fastcgi_cache_min_uses Ar number
.Bl -tag -width Ds -compact
.It default: 1
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the
.Ar number
of requests after which the response will be cached.
.It Ic fastcgi_cache_path Ar path Oo Cm levels Ns = Ns Ar levels Oc Cm keys_zone Ns = Ns Ar name Ns : Ns Ar size Oo Cm inactive Ns = Ns Ar time Oc Oo Cm max_size Ns = Ns Ar size Oc Oo Cm loader_files Ns = Ns Ar number Oc Oo Cm loader_sleep Ns = Ns Ar time Oc Oo Cm loader_threshold Ns = Ns Ar time Oc
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
Sets the path and other parameters of a cache.
Cache data are stored in files.
Both the key and file name in a cache are a result of applying the MD5 function
to the proxied URL.
The
.Ar levels
parameter defines hierarchy levels of a cache.
For example, in the following configuration
.Bd -literal -offset indent
fastcgi_cache_path /data/nginx/cache levels=1:2 keys_zone=one:10m;
.Ed
.Pp
file names in a cache will look like this:
.Bd -literal -offset indent
/data/nginx/cache/c/29/b7f54b2df7773722d382f4809d65029c
.Ed
.Pp
A cached response is first written to a temporary file, and then the file is
renamed.
Starting from version 0.8.9, temporary files and the cache can be put on
different file systems.
However, be aware that in this case a file is copied across two file systems
instead of the cheap renaming operation.
It is thus recommended that for any given location both cache and a directory
holding temporary files, set by the
.Ic fastcgi_temp_path
directive, are put on the same file system.
In addition, all active keys and information about data are stored in a shared
memory zone, whose
.Ar name
and
.Ar size
are configured by the
.Cm keys_zone
parameter.
Cached data that are not accessed during the time specified by the
.Cm inactive
parameter get removed from the cache regardless of their freshness.
By default,
.Cm inactive
is set to 10 minutes.
The special cache manager process monitors the maximum cache size set by the
.Cm max_size
parameter.
When this size is exceeded, it removes the least recently used data.
A minute after the start the special cache loader process is activated.
It loads information about previously cached data stored on file system into a
cache zone.
The loading is done in iterations.
During one iteration no more than
.Cm loader_files
items are loaded (by default, 100).
Besides, the duration of one iteration is limited by the
.Cm loader_threshold
parameter (by default, 200 milliseconds).
Between iterations, a pause configured by the
.Cm loader_sleep
parameter (by default, 50 milliseconds) is made.
.It Ic fastcgi_cache_use_stale Cm error | Cm timeout | Cm invalid_header | Cm updating | Cm http_500 | Cm http_503 | Cm http_403 | Cm http_404 | Cm off No ...
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Determines in which cases a stale cached response can be used when an error
occurs during communication with the FastCGI server.
The directive's parameters match the parameters of the
.Ic fastcgi_next_upstream
directive.
Additionally, the
.Cm updating
parameter permits using a stale cached response if it is currently being
updated.
This allows minimizing the number of accesses to FastCGI servers when updating
cached data.
To minimize the number of accesses to FastCGI servers when populating a new
cache element, the
.Ic fastcgi_cache_lock
directive can be used.
.It Ic fastcgi_cache_valid Oo Ar code No ... Oc Ar time
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets caching time for different response codes.
For example, the following directives
.Bd -literal -offset indent
fastcgi_cache_valid 200 302 10m;
fastcgi_cache_valid 404 1m;
.Ed
.Pp
set 10 minutes of caching for responses with codes 200 and 302 and 1 minute for
responses with code 404.
If only caching
.Ar time
is specified
.Bd -literal -offset indent
fastcgi_cache_valid 5m;
.Ed
.Pp
then only 200, 301, and 302 responses are cached.
In addition, the
.Cm any
parameter can be specified to cache any responses:
.Bd -literal -offset indent
fastcgi_cache_valid 200 302 10m;
fastcgi_cache_valid 301 1h;
fastcgi_cache_valid any 1m;
.Ed
.Pp
Parameters of caching can also be set directly in the response header.
This has higher priority than setting of caching time using the directive.
The X-Accel-Expires header field sets caching time of a response in seconds.
The zero value disables caching for a response.
If a value starts with the
.Qq @
prefix, it sets an absolute time in seconds since Epoch, up to which the
response may be cached.
If header does not include the X-Accel-Expires field, parameters of caching may
be set in the header fields Expires or Cache-Control .
If a header includes the Set-Cookie field, such a response will not be cached.
Processing of one or more of these response header fields can be disabled using
the
.Ic fastcgi_ignore_headers
directive.
.It Ic fastcgi_catch_stderr Ar string
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets a string to search for in the error stream of a response received from a
FastCGI server.
If the
.Ar string
is found then it is considered that the FastCGI server has returned an
.Ic fastcgi_next_upstream
invalid response.
This allows handling application errors in nginx, for example:
.Bd -literal -offset indent
location /php {
fastcgi_pass backend:9000;
...
fastcgi_catch_stderr "PHP Fatal error";
fastcgi_next_upstream error timeout invalid_header;
}
.Ed
.It Ic fastcgi_connect_timeout Ar time
.Bl -tag -width Ds -compact
.It default: 60s
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines a timeout for establishing a connection with a FastCGI server.
It should be noted that this timeout cannot usually exceed 75 seconds.
.It Ic fastcgi_hide_header Ar field
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
By default, nginx does not pass the header fields Status and X-Accel-...
from the response of a FastCGI server to a client.
The
.Ic fastcgi_hide_header
directive sets additional fields that will not be passed.
If, on the contrary, the passing of fields needs to be permitted, the
.Ic fastcgi_pass_header
directive can be used.
.It Ic fastcgi_ignore_client_abort Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Determines whether the connection with a FastCGI server should be closed when a
client closes a connection without waiting for a response.
.It Ic fastcgi_ignore_headers Ar field No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Disables processing of certain response header fields from the FastCGI server.
The following fields can be ignored: X-Accel-Redirect, X-Accel-Expires,
X-Accel-Limit-Rate (1.1.6), X-Accel-Buffering (1.1.6), X-Accel-Charset (1.1.6),
Expires, Cache-Control and Set-Cookie (0.8.44).
If not disabled, processing of these header fields has the following effect:
.Bl -bullet
.It
X-Accel-Expires, Expires, Cache-Control and Set-Cookie set the parameters of
response
.Ic fastcgi_cache_valid
caching;
.It
X-Accel-Redirect performs an
.Ic internal
redirect
to the specified URI;
.It
X-Accel-Limit-Rate sets the
.Ic limit_rate
rate
limit
for transmission of a response to a client;
.It
X-Accel-Buffering enables or disables
.Ic fastcgi_buffering
buffering
of a response;
.It
X-Accel-Charset sets the desired
.Ic charset
of a response.
.El
.It Ic fastcgi_index Ar name
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets a file name that will be appended after a URI that ends with a slash, in
the value of the
.Va $fastcgi_script_name
variable.
For example, with these settings
.Bd -literal -offset indent
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
.Ed
.Pp
and the
.Qq /page.php
request, the SCRIPT_FILENAME parameter will be equal to
.Pa /home/www/scripts/php/page.php ,
and with the
.Qq /
request it will be equal to
.Pa /home/www/scripts/php/index.php .
.It Ic fastcgi_intercept_errors Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Determines whether FastCGI server responses with codes greater than or equal to
300 should be passed to a client or be redirected to nginx for processing with
the
.Ic error_page
directive.
.It Ic fastcgi_keep_conn Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
By default, a FastCGI server will close a connection right after sending the
response.
However, when this directive is set to the value
.Cm on ,
nginx will instruct a FastCGI server to keep connections open.
This is necessary, in particular, for
.Ic keepalive
connections to FastCGI servers to function.
.It Ic fastcgi_max_temp_file_size Ar size
.Bl -tag -width Ds -compact
.It default: 1024m
.It context: Ic http , Ic server , Ic location
.El
.Pp
When buffering of responses from the FastCGI server is enabled, and the whole
response does not fit into the memory buffers set by the
.Ic fastcgi_buffer_size
and
.Ic fastcgi_buffers
directives, a part of the response can be saved to a temporary file.
This directive sets the maximum
.Ar size
of a temporary file.
The size of data written to a temporary file at a time is set by the
.Ic fastcgi_temp_file_write_size
directive.
The zero value disables buffering of responses to temporary files.
.It Ic fastcgi_next_upstream Cm error | Cm timeout | Cm invalid_header | Cm http_500 | Cm http_503 | Cm http_403 | Cm http_404 | Cm off No ...
.Bl -tag -width Ds -compact
.It default: Cm error Cm timeout
.It context: Ic http , Ic server , Ic location
.El
.Pp
Specifies in which cases a request should be passed to the next server:
.Bl -tag -width Ds
.It Cm error
an error occurred while establishing a connection with the server, passing a
request to it, or reading the response header;
.It Cm timeout
a timeout has occurred while establishing a connection with the server, passing
a request to it, or reading the response header;
.It Cm invalid_header
a server returned an empty or invalid response;
.It Cm http_500
a server returned a response with the code 500;
.It Cm http_503
a server returned a response with the code 503;
.It Cm http_403
a server returned a response with the code 403;
.It Cm http_404
a server returned a response with the code 404;
.It Cm off
disables passing a request to the next server.
.El
.Pp
One should bear in mind that passing a request to the next server is only
possible if nothing has been sent to a client yet.
That is, if an error or timeout occurs in the middle of the transferring of a
response, fixing this is impossible.
The directive also defines what is considered an unsuccessful attempt of
communication with a server.
The cases of
.Cm error ,
.Cm timeout
and
.Cm invalid_header
are always considered unsuccessful attempts, even if they are not specified in
the directive.
The cases of
.Cm http_500
and
.Cm http_503
are considered unsuccessful attempts only if they are specified in the
directive.
The cases of
.Cm http_403
and
.Cm http_404
are never considered unsuccessful attempts.
.It Ic fastcgi_no_cache Ar string No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines conditions under which the response will not be saved to a cache.
If at least one value of the
.Ar string
parameters is not empty and is not equal to 0 then the response will not be
saved:
.Bd -literal -offset indent
fastcgi_no_cache $cookie_nocache $arg_nocache$arg_comment;
fastcgi_no_cache $http_pragma $http_authorization;
.Ed
.Pp
Can be used along with the
.Ic fastcgi_cache_bypass
directive.
.It Ic fastcgi_param Ar parameter Ar value Oo Cm if_not_empty Oc
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets a
.Ar parameter
that should be passed to the FastCGI server.
A
.Ar value
can contain text, variables, and their combination.
These directives are inherited from the previous level if and only if there are
no
.Ic fastcgi_param
directives defined on the current level.
The following example shows the minimum required settings for PHP:
.Bd -literal -offset indent
fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
.Ed
.Pp
The SCRIPT_FILENAME parameter is used in PHP for determining the script name,
and the QUERY_STRING parameter is used to pass request parameters.
For scripts that process POST requests, the following three parameters are
also required:
.Bd -literal -offset indent
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
.Ed
.Pp
If PHP was built with the
.Fl -enable-force-cgi-redirect
configuration parameter, the REDIRECT_STATUS parameter should also be passed
with the value 200:
.Bd -literal -offset indent
fastcgi_param REDIRECT_STATUS 200;
.Ed
.Pp
If a directive is specified with
.Cm if_not_empty
(1.1.11) then such a parameter will not be passed to the server until its value
is not empty:
.Bd -literal -offset indent
fastcgi_param HTTPS $https if_not_empty;
.Ed
.It Ic fastcgi_pass Ar address
.Bl -tag -width Ds -compact
.It default:
.It context: Ic location , Ic if in location
.El
.Pp
Sets the address of a FastCGI server.
The address can be specified as a domain name or IP address, and an optional
port:
.Bd -literal -offset indent
fastcgi_pass localhost:9000;
.Ed
.Pp
or as a UNIX-domain socket path:
.Bd -literal -offset indent
fastcgi_pass unix:/tmp/fastcgi.socket;
.Ed
.Pp
If a domain name resolves to several addresses, all of them will be used in a
round-robin fashion.
In addition, an address can be specified as a server group.
.It Ic fastcgi_pass_header Ar field
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Permits passing
.Ic fastcgi_hide_header
otherwise disabled
header fields from a FastCGI server to a client.
.It Ic fastcgi_read_timeout Ar time
.Bl -tag -width Ds -compact
.It default: 60s
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines a timeout for reading a response from the FastCGI server.
A timeout is set only between two successive read operations, not for the
transmission of the whole response.
If a FastCGI server does not transmit anything within this time, a connection is
closed.
.It Ic fastcgi_pass_request_body Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server , Ic location
.El
.Pp
Indicates whether the original request body is passed to the FastCGI server.
See also the
.Ic fastcgi_pass_request_headers
directive.
.It Ic fastcgi_pass_request_headers Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server , Ic location
.El
.Pp
Indicates whether the header fields of the original request are passed to the
FastCGI server.
See also the
.Ic fastcgi_pass_request_body
directive.
.It Ic fastcgi_send_lowat Ar size
.Bl -tag -width Ds -compact
.It default: 0
.It context: Ic http , Ic server , Ic location
.El
.Pp
If the directive is set to a non-zero value, nginx will try to minimize the
number of send operations on outgoing connections to a FastCGI server by using
either
.Dv NOTE_LOWAT
flag of the
.Cm kqueue
method, or the
.Dv SO_SNDLOWAT
socket option, with the specified
.Ar size .
This directive is ignored on Linux, Solaris, and Windows.
.It Ic fastcgi_send_timeout Ar time
.Bl -tag -width Ds -compact
.It default: 60s
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets a timeout for transmitting a request to the FastCGI server.
A timeout is set only between two successive write operations, not for the
transmission of the whole request.
If a FastCGI server does not receive anything within this time, a connection is
closed.
.It Ic fastcgi_split_path_info Ar regex
.Bl -tag -width Ds -compact
.It default:
.It context: Ic location
.El
.Pp
Defines a regular expression that captures a value for the
.Va $fastcgi_path_info
variable.
A regular expression should have two captures: the first becomes a value of the
.Va $fastcgi_script_name
variable, the second becomes a value of the
.Va $fastcgi_path_info
variable.
For example, with these settings
.Bd -literal -offset indent
location ~ ^(.+\\.php)(.*)$ {
fastcgi_split_path_info ^(.+\\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME /path/to/php$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
.Ed
.Pp
and the
.Qq /show.php/article/0001
request, the SCRIPT_FILENAME
parameter will be equal to
.Pa /path/to/php/show.php ,
and the PATH_INFO
parameter will be equal to
.Pa /article/0001 .
.It Ic fastcgi_store Cm on | Cm off | Ar string
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables saving of files to a disk.
The
.Cm on
parameter saves files with paths corresponding to the directives
.Ic alias
or
.Ic root.
The
.Cm off
parameter disables saving of files.
In addition, the file name can be set explicitly using the
.Ar string
with variables:
.Bd -literal -offset indent
fastcgi_store /data/www$original_uri;
.Ed
.Pp
The modification time of files is set according to the received Last-Modified
response header field.
A response is first written to a temporary file, and then the file is renamed.
Starting from version 0.8.9, temporary files and the persistent store can be put
on different file systems.
However, be aware that in this case a file is copied across two file systems
instead of the cheap renaming operation.
It is thus recommended that for any given location both saved files and a
directory holding temporary files, set by the
.Ic fastcgi_temp_path
directive, are put on the same file system.
This directive can be used to create local copies of static unchangeable files,
e.g.:
.Bd -literal -offset indent
location /images/ {
root /data/www;
open_file_cache_errors off;
error_page 404 = /fetch$uri;
}
location /fetch/ {
internal;
fastcgi_pass backend:9000;
...
fastcgi_store on;
fastcgi_store_access user:rw group:rw all:r;
fastcgi_temp_path /data/temp;
alias /data/www/;
}
.Ed
.It Ic fastcgi_store_access Ar users Ns : Ns Ar permissions No ...
.Bl -tag -width Ds -compact
.It default: user:rw
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets access permissions for newly created files and directories, e.g.:
.Bd -literal -offset indent
fastcgi_store_access user:rw group:rw all:r;
.Ed
.Pp
If any
.Ar group
or
.Cm all
access permissions are specified then
.Ar user
permissions may be omitted:
.Bd -literal -offset indent
fastcgi_store_access group:rw all:r;
.Ed
.It Ic fastcgi_temp_file_write_size Ar size
.Bl -tag -width Ds -compact
.It default: 8k | 16k
.It context: Ic http , Ic server , Ic location
.El
.Pp
Limits the
.Ar size
of data written to a temporary file at a time, when buffering of responses from
the FastCGI server to temporary files is enabled.
By default,
.Ar size
is limited by two buffers set by the
.Ic fastcgi_buffer_size
and
.Ic fastcgi_buffers
directives.
The maximum size of a temporary file is set by the
.Ic fastcgi_max_temp_file_size
directive.
.It Ic fastcgi_temp_path Ar path Oo Ar level1 Oo Ar level2 Oo Ar level3 Oc Oc Oc
.Bl -tag -width Ds -compact
.It default: fastcgi_temp
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines a directory for storing temporary files with data received from FastCGI
servers.
Up to three-level subdirectory hierarchy can be used underneath the specified
directory.
For example, in the following configuration
.Bd -literal -offset indent
fastcgi_temp_path /spool/nginx/fastcgi_temp 1 2;
.Ed
.Pp
a temporary file might look like this:
.Bd -literal -offset indent
/spool/nginx/fastcgi_temp/7/45/00000123457
.Ed
.El
.Ss Module ngx_http_flv_module
.Em This module is not enabled on OpenBSD.
.Bl -tag -width Ds
.It Ic flv
.Bl -tag -width Ds -compact
.It default:
.It context: Ic location
.El
.Pp
Turns on module processing in a surrounding location.
.El
.Ss Module ngx_http_geo_module
.Bl -tag -width Ds
.It Ic geo Oo Ar $address Oc Ar $variable Brq No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
Describes the dependency of values of the specified variable on the client IP
address.
By default, the address is taken from the
.Va $remote_addr
variable, but it can also be taken from another variable (0.7.27), for example:
.Bd -literal -offset indent
geo $arg_remote_addr $geo {
...;
}
.Ed
.Pp
Since variables are evaluated only when used, the mere existence of even a large
number of declared
.Ic geo
variables does not cause any extra costs for request processing.
If the value of a variable does not represent a valid IP address then the
255.255.255.255
address is used.
Addresses are specified either as prefixes in CIDR notation (including
individual addresses) or as ranges (0.7.23).
IPv6 prefixes are supported starting from versions 1.3.10 and 1.2.7.
The following special parameters are also supported:
.Bl -tag -width Ds
.It Cm delete
deletes the specified network (0.7.23).
.It Cm default
a value set to the variable if the client address does not match any of the
specified addresses.
When addresses are specified in CIDR notation,
0.0.0.0/0
and
::/0
can be used instead of
.Cm default.
When
.Cm default
is not specified, the default value will be an empty string.
.It Cm include
includes a file with addresses and values.
There can be several inclusions.
.It Cm proxy
defines trusted addresses (0.8.7, 0.7.63).
When a request comes from a trusted address, an address from the X-Forwarded-For
request header field will be used instead.
In contrast to the regular addresses, trusted addresses are checked
sequentially.
Trusted IPv6 addresses are supported starting from versions 1.3.0 and 1.2.1.
.It Cm proxy_recursive
enables recursive address search (1.3.0, 1.2.1).
If recursive search is disabled then instead of the original client address that
matches one of the trusted addresses, the last address sent in X-Forwarded-For
will be used.
If recursive search is enabled then instead of the original client address that
matches one of the trusted addresses, the last non-trusted address sent in
X-Forwarded-For will be used.
.It Cm ranges
indicates that addresses are specified as ranges (0.7.23).
This parameter should be the first.
To speed up loading of a geo base, addresses should be put in ascending order.
.El
.Pp
Example:
.Bd -literal -offset indent
geo $country {
default ZZ;
include conf/geo.conf;
delete 127.0.0.0/16;
proxy 192.168.100.0/24;
proxy 2001:0db8::/32;
127.0.0.0/24 US;
127.0.0.1/32 RU;
10.1.0.0/16 RU;
192.168.1.0/24 UK;
}
.Ed
.Pp
The
.Pa conf/geo.conf
file could contain the following lines:
.Bd -literal -offset indent
10.2.0.0/16 RU;
192.168.2.0/24 RU;
.Ed
.Pp
A value of the most specific match is used.
For example, for the 127.0.0.1 address the value
RU
will be chosen, not
US .
Example with ranges:
.Bd -literal -offset indent
geo $country {
ranges;
default ZZ;
127.0.0.0-127.0.0.0 US;
127.0.0.1-127.0.0.1 RU;
127.0.0.1-127.0.0.255 US;
10.1.0.0-10.1.255.255 RU;
192.168.1.0-192.168.1.255 UK;
}
.Ed
.El
.Ss Module ngx_http_geoip_module
.Em This module is not enabled on OpenBSD.
.Bl -tag -width Ds
.It Ic geoip_country Ar file
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
Specifies a database used to determine the country depending on the client IP
address.
The following variables are available when using this database:
.Bl -tag -width Ds
.It Va $geoip_country_code
two-letter country code, for example, RU, US.
.It Va $geoip_country_code3
three-letter country code, for example, RUS, USA.
.It Va $geoip_country_name
country name, for example, Russian Federation, United States.
.El
.It Ic geoip_city Ar file
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
Specifies a database used to determine the country, region, and city depending
on the client IP address.
The following variables are available when using this database:
.Bl -tag -width Ds
.It Va $geoip_area_code
telephone area code (US only).
This variable may contain outdated information since the corresponding database
field is deprecated.
.It Va $geoip_city_continent_code
two-letter continent code, for example, EU, NA.
.It Va $geoip_city_country_code
two-letter country code, for example, RU, US.
.It Va $geoip_city_country_code3
three-letter country code, for example, RUS, USA.
.It Va $geoip_city_country_name
country name, for example, Russian Federation, United States.
.It Va $geoip_dma_code
DMA region code in US (also known as metro code), according to the
geotargeting in Google AdWords API.
.It Va $geoip_latitude
latitude.
.It Va $geoip_longitude
longitude.
.It Va $geoip_region
two-symbol country region code (region, territory, state, province, federal
land and the like), for example, 48, DC.
.It Va $geoip_region_name
country region name (region, territory, state, province, federal land and the
like), for example, Moscow City, District of Columbia.
.It Va $geoip_city
city name, for example, Moscow, Washington.
.It Va $geoip_postal_code
postal code.
.El
.It Ic geoip_org Ar file
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
Specifies a database used to determine the organization depending on the client
IP address.
The following variable is available when using this database:
.Bl -tag -width Ds
.It Va $geoip_org
organization name, for example, The University of Melbourne.
.El
.It Ic geoip_proxy Ar address | Ar CIDR
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
Defines trusted addresses.
When a request comes from a trusted address, an address from the X-Forwarded-For
request header field will be used instead.
.It Ic geoip_proxy_recursive Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http
.El
.Pp
If recursive search is disabled then instead of the original client address that
matches one of the trusted addresses, the last address sent in X-Forwarded-For
will be used.
If recursive search is enabled then instead of the original client address that
matches one of the trusted addresses, the last non-trusted address sent in
X-Forwarded-For will be used.
.El
.Ss Module ngx_http_gunzip_module
.Em This module is not enabled on OpenBSD.
.Bl -tag -width Ds
.It Ic gunzip Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables decompression of gzipped responses for clients that lack
gzip support.
If enabled, the following directives are also taken into account when
determining if clients support gzip:
.Ic gzip_http_version ,
.Ic gzip_proxied ,
and
.Ic gzip_disable.
See also the
.Ic gzip_vary
directive.
.It Ic gunzip_buffers Ar number Ar size
.Bl -tag -width Ds -compact
.It default: 32 4k | 16 8k
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the
.Ar number
and
.Ar size
of buffers used to decompress a response.
By default, the buffer size is equal to one memory page.
This is either 4K or 8K, depending on a platform.
.El
.Ss Module ngx_http_gzip_module
.Bl -tag -width Ds
.It Ic gzip Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location , Ic if in location
.El
.Pp
Enables or disables gzipping of responses.
.It Ic gzip_buffers Ar number Ar size
.Bl -tag -width Ds -compact
.It default: 32 4k | 16 8k
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the
.Ar number
and
.Ar size
of buffers used to compress a response.
By default, the buffer size is equal to one memory page.
This is either 4K or 8K, depending on a platform.
Until version 0.7.28, four 4K or 8K buffers were used by default.
.It Ic gzip_comp_level Ar level
.Bl -tag -width Ds -compact
.It default: 1
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets a gzip compression
.Ar level
of a response.
Acceptable values are in the range from 1 to 9.
.It Ic gzip_disable Ar regex No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Disables gzipping of responses for requests with User-Agent header fields
matching any of the specified regular expressions.
The special mask
.Cm msie6
(0.7.12) corresponds to the regular expression
.Qq MSIE Ns Oo 4-6 Oc \\. ,
but works faster.
Starting from version 0.8.11,
.Qq MSIE 6.0; ... SV1
is excluded from this mask.
.It Ic gzip_min_length Ar length
.Bl -tag -width Ds -compact
.It default: 20
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the minimum length of a response that will be gzipped.
The length is determined only from the Content-Length response header field.
.It Ic gzip_http_version Cm 1.0 | Cm 1.1
.Bl -tag -width Ds -compact
.It default: 1.1
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the minimum HTTP version of a request required to compress a response.
.It Ic gzip_proxied Cm off | Cm expired | Cm no-cache | Cm no-store | Cm private | Cm no_last_modified | Cm no_etag | Cm auth | Cm any No ...
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables gzipping of responses for proxied requests depending on the
request and response.
The fact that the response is proxied is determined by the presence of the Via
request header field.
A directive accepts multiple parameters:
.Bl -tag -width Ds
.It Cm off
disables compression for all proxied requests, ignoring other parameters;
.It Cm expired
enables compression if a response header includes the Expires field with a value
that disables caching;
.It Cm no-cache
enables compression if a response header includes the Cache-Control field with
the
.Cm no-cache
parameter;
.It Cm no-store
enables compression if a response header includes the Cache-Control field with
the
.Cm no-store
parameter;
.It Cm private
enables compression if a response header includes the Cache-Control field with
the
.Cm private
parameter;
.It Cm no_last_modified
enables compression if a response header does not include the Last-Modified
field;
.It Cm no_etag
enables compression if a response header does not include the ETag field;
.It Cm auth
enables compression if a request header includes the Authorization field;
.It Cm any
enables compression for all proxied requests.
.El
.It Ic gzip_types Ar mime-type No ...
.Bl -tag -width Ds -compact
.It default: text/html
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables gzipping of responses for the specified MIME types in addition to
.Ar text/html.
The special value
.Qq *
matches any MIME type (0.8.29).
Responses with the
.Ar text/html
type are always compressed.
.It Ic gzip_vary Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables inserting the Vary: Accept-Encoding response header field if
the directives
.Ic gzip ,
.Ic gzip_static ,
or
.Ic gunzip
are active.
.El
.Ss Module ngx_http_gzip_static_module
.Bl -tag -width Ds
.It Ic gzip_static Cm on | Cm off | Cm always
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables
.Pq Ic on
or disables
.Pq Ic off
checking the existence of precompressed files.
The following directives are also taken into account:
.Ic gzip_http_version ,
.Ic gzip_proxied ,
.Ic gzip_disable ,
and
.Ic gzip_vary .
With the
.Cm always
value (1.3.6), gzipped file is used in all cases, without checking if the client
supports it.
It is useful if there are no uncompressed files on the disk anyway or the
.Sx Module ngx_http_gunzip_module
is used.
The files can be compressed using the
.Ic gzip
command, or any other compatible one.
It is recommended that the modification date and time of original and compressed
files be the same.
.El
.Ss Module ngx_http_headers_module
.Bl -tag -width Ds
.It Ic add_header Ar name Ar value
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location , Ic if in location
.El
.Pp
Adds the specified field to a response header provided that the response code
equals 200, 201, 204, 206, 301, 302, 303, 304, or 307.
A value can contain variables.
.It Ic expires Oo Cm modified Oc Ar time
.It Ic expires Cm epoch | Cm max | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location , Ic if in location
.El
.Pp
Enables or disables adding or modifying the Expires and Cache-Control response
header fields provided that the response code equals 200, 201, 204, 206, 301,
302, 303, 304, or 307.
A parameter can be a positive or negative
.Ar time .
A time in the Expires field is computed as a sum of the current time and
.Ar time
specified in the directive.
If the
.Cm modified
parameter is used (0.7.0, 0.6.32) then time is computed as a sum of the file's
modification time and
.Ar time
specified in the directive.
In addition, it is possible to specify a time of the day using the
.Qq @
prefix (0.7.9, 0.6.34):
.Bd -literal -offset indent
expires @15h30m;
.Ed
.Pp
The
.Cm epoch
parameter corresponds to the absolute time
Thu, 01 Jan 1970 00:00:01 GMT.
The contents of the Cache-Control field depends on the sign of the specified
time:
.Bl -bullet
.It
time is negative - Cache-Control: no-cache.
.It
time is positive or zero - Cache-Control: max-age=t, where t is a time
specified in the directive, in seconds.
.El
.Pp
The
.Cm max
parameter sets Expires to the value
.Qq Thu, 31 Dec 2037 23:55:55 GMT ,
and Cache-Control to 10 years.
The
.Cm off
parameter disables adding or modifying the Expires and Cache-Control response
header fields.
.El
.Ss Module ngx_http_hls_module
.Em This module is only available in the commercial version of nginx.
.Bl -tag -width Ds
.It Ic hls
.Bl -tag -width Ds -compact
.It default:
.It context: Ic location
.El
.Pp
Turns on HLS streaming in the surrounding location.
.It Ic hls_buffers Ar number Ar size
.Bl -tag -width Ds -compact
.It default: 8 2m
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the maximum
.Ar number
and
.Ar size
of buffers that are used for reading and writing data frames.
.It Ic hls_fragment Ar time
.Bl -tag -width Ds -compact
.It default: 5s
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines the default fragment length for playlist URIs requested without the
len
argument.
.It Ic hls_mp4_buffer_size Ar size
.Bl -tag -width Ds -compact
.It default: 512k
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the initial
.Ar size
of the memory buffer used to process MP4 files.
.It Ic hls_mp4_max_buffer_size Ar size
.Bl -tag -width Ds -compact
.It default: 10m
.It context: Ic http , Ic server , Ic location
.El
.Pp
During metadata processing, a larger buffer may become necessary.
Its size cannot exceed the specified
.Ar size ,
or else nginx will return the server error 500 (Internal Server Error), and
log the following message:
.Bd -literal -offset indent
"/some/movie/file.mp4" mp4 moov atom is too large:
12583268, you may want to increase hls_mp4_max_buffer_size
.Ed
.El
.Ss Module ngx_http_image_filter_module
.Em This module is not enabled on OpenBSD.
.Bl -tag -width Ds
.It Ic image_filter Cm off
.It Ic image_filter Cm test
.It Ic image_filter Cm size
.It Ic image_filter Cm rotate Cm 90 | Cm 180 | Cm 270
.It Ic image_filter Cm resize Ar width Ar height
.It Ic image_filter Cm crop Ar width Ar height
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic location
.El
.Pp
Sets the type of transformation to perform on images:
.Bl -tag -width Ds
.It Cm off
turns off module processing in a surrounding location.
.It Cm test
ensures that responses are images in either JPEG, GIF, or PNG format.
Otherwise, the 415 (Unsupported Media Type) error is returned.
.It Cm size
outputs information about images in a JSON format, e.g.:
.Bd -literal -offset indent
{ "img" : { "width": 100, "height": 100, "type": "gif" } }
.Ed
.Pp
In case of an error, the output is as follows:
.Bd -literal -offset indent
{}
.Ed
.It Cm rotate Cm 90 | Cm 180 | Cm 270
rotates images counter-clockwise by the specified number of degrees.
Parameter value can contain variables.
This mode can be used either alone or along with the
.Cm resize
and
.Cm crop
transformations.
.It Cm resize Ar width Ar height
proportionally reduces an image to the specified sizes.
To reduce by only one dimension, another dimension can be specified as
.Qq - .
In case of an error, the server will return code 415 (Unsupported Media Type).
Parameter values can contain variables.
When used along with the
.Cm rotate
parameter, the rotation happens after reduction.
.It Cm crop Ar width Ar height
proportionally reduces an image to the larger side size and crops extraneous
edges by another side.
To reduce by only one dimension, another dimension can be specified as
.Qq - .
In case of an error, the server will return code 415 (Unsupported Media Type).
Parameter values can contain variables.
When used along with the
.Cm rotate
parameter, the rotation happens before reduction.
.El
.It Ic image_filter_buffer Ar size
.Bl -tag -width Ds -compact
.It default: 1M
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the maximum size of the buffer used for reading images.
When the size is exceeded the server returns error 415 (Unsupported Media Type).
.It Ic image_filter_interlace Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
If enabled, final images will be interlaced.
For JPEG, final images will be in progressive JPEG format.
.It Ic image_filter_jpeg_quality Ar quality
.Bl -tag -width Ds -compact
.It default: 75
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the desired
.Ar quality
of the transformed JPEG images.
Acceptable values are in the range from 1 to 100.
Lesser values usually imply both lower image quality and less data to transfer.
The maximum recommended value is 95.
Parameter value can contain variables.
.It Ic image_filter_sharpen Ar percent
.Bl -tag -width Ds -compact
.It default: 0
.It context: Ic http , Ic server , Ic location
.El
.Pp
Increases sharpness of the final image.
The sharpness percentage can exceed 100.
The zero value disables sharpening.
Parameter value can contain variables.
.It Ic image_filter_transparency Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines whether transparency should be preserved when transforming GIF images or
PNG images with colors specified by a palette.
The loss of transparency results in images of a better quality.
The alpha channel transparency in PNG is always preserved.
.El
.Ss Module ngx_http_index_module
.Bl -tag -width Ds
.It Ic index Ar file No ...
.Bl -tag -width Ds -compact
.It default: Pa index.html
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines files that will be used as an index.
The
.Ar file
name can contain variables.
Files are checked in the specified order.
The last element of the list can be a file with an absolute path.
Example:
.Bd -literal -offset indent
index index.$geo.html index.0.html /index.html;
.Ed
.Pp
It should be noted that using an index file causes an internal redirect, and the
request can be processed in a different location.
For example, with the following configuration:
.Bd -literal -offset indent
location = / {
index index.html;
}
location / {
...
}
.Ed
.Pp
a
.Qq /
request will actually be processed in the second location as
.Pa /index.html .
.El
.Ss Module ngx_http_limit_conn_module
.Bl -tag -width Ds
.It Ic limit_conn Ar zone Ar number
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the shared memory zone and the maximum allowed number of connections for a
given key value.
When this limit is exceeded, the server will return the 503 (Service Temporarily
Unavailable) error in reply to a request.
For example, the directives
.Bd -literal -offset indent
limit_conn_zone $binary_remote_addr zone=addr:10m;
server {
location /download/ {
limit_conn addr 1;
}
.Ed
.Pp
allow only one connection per an IP address at a time.
When several
.Ic limit_conn
directives are specified, any configured limit will apply.
For example, the following configuration will limit the number of connections to
the server per a client IP and, at the same time, the total number of
connections to the virtual host:
.Bd -literal -offset indent
limit_conn_zone $binary_remote_addr zone=perip:10m;
limit_conn_zone $server_name zone=perserver:10m;
server {
...
limit_conn perip 10;
limit_conn perserver 100;
}
.Ed
.Pp
These directives are inherited from the previous level if and only if there are
no
.Ic limit_conn
directives on the current level.
.It Ic limit_conn_log_level Cm info | Cm notice | Cm warn | Cm error
.Bl -tag -width Ds -compact
.It default: Cm error
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the desired logging level for cases when the server limits the number of
connections.
.It Ic limit_conn_status Ar code
.Bl -tag -width Ds -compact
.It default: 503
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the status code to return in response to rejected requests.
.It Ic limit_conn_zone Ar $variable Cm zone Ns = Ns Ar name Ns : Ns Ar size
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
Sets parameters for a shared memory zone that will keep states for various keys.
In particular, the state includes the current number of connections.
The key is any non-empty value of the specified variable (empty values are not
accounted).
Usage example:
.Bd -literal -offset indent
limit_conn_zone $binary_remote_addr zone=addr:10m;
.Ed
.Pp
Here, a client IP address serves as a key.
Note that instead of
.Va $remote_addr ,
the
.Va $binary_remote_addr
variable is used here.
The
.Va $remote_addr
variable's size can vary from 7 to 15 bytes.
The stored state occupies either 32 or 64 bytes of memory on 32-bit platforms
and always 64 bytes on 64-bit platforms.
The
.Va $binary_remote_addr
variable's size is always 4 bytes.
The stored state always occupies 32 bytes on 32-bit platforms and 64 bytes on
64-bit platforms.
One megabyte zone can keep about 32 thousand 32-byte states or about 16 thousand
64-byte states.
If the zone storage is exhausted, the server will return the 503 (Service
Temporarily Unavailable) error to all further requests.
.It Ic limit_zone Ar name Ar $variable Ar size
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
This directive is made obsolete in version 1.1.8, an equivalent
.Ic limit_conn_zone
directive with a changed syntax should be used instead:
.Ic limit_conn_zone Ar $variable Cm zone Ns = Ns Ar name Ns : Ns Ar size ;
.El
.Ss Module ngx_http_limit_req_module
.Bl -tag -width Ds
.It Ic limit_req Cm zone Ns = Ns Ar name Oo Cm burst Ns = Ns Ar number Oc Oo Cm nodelay Oc
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the shared memory zone and the maximum burst size of requests.
If the requests rate exceeds the rate configured for a zone, their processing is
delayed such that requests are processed at a defined rate.
Excessive requests are delayed until their number exceeds the maximum burst size
in which case the request is terminated with an error 503 (Service Temporarily
Unavailable).
By default, the maximum burst size is equal to zero.
For example, the directives
.Bd -literal -offset indent
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
server {
location /search/ {
limit_req zone=one burst=5;
}
.Ed
.Pp
allow not more than 1 request per second at an average, with bursts not
exceeding 5 requests.
If delaying of excessive requests while requests are being limited is not
desired, the parameter
.Cm nodelay
should be used:
.Bd -literal -offset indent
limit_req zone=one burst=5 nodelay;
.Ed
.It Ic limit_req_log_level Cm info | Cm notice | Cm warn | Cm error
.Bl -tag -width Ds -compact
.It default: Cm error
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the desired logging level for cases when the server refuses to process
requests due to rate exceeding, or delays request processing.
Logging level for delays is one point less than for refusals; for example, if
.Ic limit_req_log_level notice
is specified, delays are logged with the
.Cm info
level.
.It Ic limit_req_status Ar code
.Bl -tag -width Ds -compact
.It default: 503
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the status code to return in response to rejected requests.
.It Ic limit_req_zone Ar $variable Cm zone Ns = Ns Ar name Ns : Ns Ar size Cm rate Ns = Ns Ar rate
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
Sets parameters for a shared memory zone that will keep states for various keys.
In particular, the state stores the current number of excessive requests.
The key is any non-empty value of the specified variable (empty values are not
accounted).
Usage example:
.Bd -literal -offset indent
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
.Ed
.Pp
Here, the states are kept in a 10 megabyte zone one, and an average request
processing rate for this zone cannot exceed 1 request per second.
A client IP address serves as a key.
Note that instead of
.Va $remote_addr ,
the
.Va $binary_remote_addr
variable is used here, that allows to decrease the state size down to 64 bytes.
One megabyte zone can keep about 16 thousand 64-byte states.
If the zone storage is exhausted, the server will return the 503 (Service
Temporarily Unavailable) error to all further requests.
The rate is specified in requests per second (r/s).
If a rate of less than one request per second is desired, it is specified in
request per minute (r/m).
For example, half-request per second is 30r/m.
.El
.Ss Module ngx_http_log_module
.Bl -tag -width Ds
.It Ic access_log Ar path Oo Ar format Oo Cm buffer Ns = Ns Ar size \
Oo Cm flush Ns = Ns Ar time Oc Oc Oc
.It Ic access_log Ar path Ar format Cm gzip Ns Oo = Ns level Oc \
Oo Cm buffer Ns = Ns Ar size Oc Oo Cm flush Ns = Ns Ar time Oc
.It Ic access_log Cm syslog : Ns Cm server Ns = Ns Ar address \
Oo , Ar parameter Ns = Ns Ar value Oc Oo Ar format Oc
.It Ic access_log Cm off
.Bl -tag -width Ds -compact
.It default: Pa logs/access.log Cm combined
.It context: Ic http , Ic server , Ic location , Ic if in location , Ic limit_except
.El
.Pp
Sets the path, format, and configuration for a buffered log write.
Several logs can be specified on the same level.
Logging to syslog can be configured by specifying the
.Cm syslog:
prefix in the first parameter.
The special value
.Cm off
cancels all
.Ic access_log
directives on the current level.
If the format is not specified then the predefined
combined
format is used.
If either the
.Cm buffer
or
.Ic gzip
(1.3.10, 1.2.7) parameter is used, writes to log will be buffered.
The buffer size must not exceed the size of an atomic write to a disk file.
For FreeBSD this size is unlimited.
When buffering is enabled, the data will be written to the file:
.Bl -bullet
.It
if the next log line does not fit into the buffer;
.It
if the buffered data is older than specified by the
.Cm flush
parameter (1.3.10, 1.2.7);
.It
when a worker process is
re-opening
log files or is shutting down.
.El
.Pp
If the
.Ic gzip
parameter is used, then the buffered data will be compressed before writing to
the file.
The compression level can be set between 1 (fastest, less compression) and 9
(slowest, best compression).
By default, the buffer size is equal to 64K bytes, and the compression level is
set to 1.
Since the data is compressed in atomic blocks, the log file can be decompressed
or read by
.Ic zcat
at any time.
Example:
.Bd -literal -offset indent
access_log /path/to/log.gz combined gzip flush=5m;
.Ed
.Pp
For gzip compression to work, nginx must be built with the zlib library.
The file path can contain variables (0.7.6+), but such logs have some
constraints:
.Bl -bullet
.It
the
.Ar user
whose credentials are used by worker processes should have permissions to create
files in a directory with such logs;
.It
buffered writes do not work;
.It
the file is opened and closed for each log write.
However, since the descriptors of frequently used files can be stored in a
.Ic open_log_file_cache
cache, writing to the old file can continue during the time specified by the
.Ic open_log_file_cache
directive's
.Cm valid
parameter
.It
during each log write the existence of the request's root directory is checked,
and if it does not exist the log is not created.
It is thus a good idea to specify both
.Ic root
and
.Ic access_log
on the same level:
.Bd -literal -offset indent
server {
root /spool/vhost/data/$host;
access_log /spool/vhost/logs/$host;
...
.Ed
.El
.Pp
The following parameters configure logging to syslog:
.Bl -tag -width Ds
.It Cm server Ns = Ns Ar address
Defines the address of a syslog server.
The address can be specified as a domain name, IP address, or a UNIX-domain
socket path (specified after the
.Cm unix:
prefix).
With a domain name or IP address, the port can be specified.
If port is not specified, the port 514 is used.
If a domain name resolves to several IP addresses, the first resolved address is
used.
.It Cm facility Ns = Ns Ar string
Sets facility of syslog messages, as defined in
RFC 3164.
Facility can be one of
.Cm kern ,
.Cm user ,
.Cm mail ,
.Cm daemon ,
.Cm auth ,
.Cm intern ,
.Cm lpr ,
.Cm news ,
.Cm uucp ,
.Cm clock ,
.Cm authpriv ,
.Cm ftp ,
.Cm ntp ,
.Cm audit ,
.Cm alert ,
.Cm cron ,
.Cm local0 No .. Cm local7.
Default is
.Cm local7 .
.It Cm severity Ns = Ns Ar string
Sets severity of syslog messages, as defined in RFC 3164.
Possible values are the same as for the second parameter (level) of the
.Ic error_log
directive.
Default is
.Cm info .
.It Cm tag Ns = Ns Ar string
Sets the tag of syslog messages.
Default is
.Qq nginx .
.El
.Pp
Example syslog configuration:
.Bd -literal -offset indent
access_log syslog:server=192.168.1.1;
access_log syslog:server=unix:/var/log/nginx.sock;
access_log syslog:server=[2001:db8::1]:12345,facility=local7,tag=nginx,severity=info combined;
.Ed
.It Ic log_format Ar name Ar string No ...
.Bl -tag -width Ds -compact
.It default: combined Qq ...
.It context: Ic http
.El
.Pp
Specifies log format.
The log format can contain common variables, and variables that exist only at
the time of a log write:
.Bl -tag -width Ds
.It Va $bytes_sent
the number of bytes sent to a client
.It Va $connection
connection serial number
.It Va $connection_requests
the current number of requests made through a connection (1.1.18)
.It Va $msec
time in seconds with a milliseconds resolution at the time of the log write
.It Va $pipe
.Qq p
if request was pipelined,
.Qo . Qc
otherwise
.It Va $request_length
request length (including request line, header, and request body)
.It Va $request_time
request processing time in seconds with a milliseconds resolution; time elapsed
between the first bytes were read from the client and the log write after the
last bytes were sent to the client
.It Va $status
response status
.It Va $time_iso8601
local time in the ISO 8601 standard format
.It Va $time_local
local time in the Common Log Format
.El
.Pp
In the modern nginx versions variables
.Va $status
(1.3.2, 1.2.2),
.Va $bytes_sent
(1.3.8, 1.2.5),
.Va $connection
(1.3.8, 1.2.5),
.Va $connection_requests
(1.3.8, 1.2.5),
.Va $msec
(1.3.9, 1.2.6),
.Va $request_time
(1.3.9, 1.2.6),
.Va $pipe
(1.3.12, 1.2.7),
.Va $request_length
(1.3.12, 1.2.7),
.Va $time_iso8601
(1.3.12, 1.2.7), and
.Va $time_local
(1.3.12, 1.2.7) are also available as common variables.
Header lines sent to a client have the prefix sent_http_, for example,
.Va $sent_http_content_range .
The configuration always includes the predefined
.Cm combined
format:
.Bd -literal -offset indent
log_format combined '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
.Ed
.It Ic open_log_file_cache Cm max Ns = Ns Ar N Oo Cm inactive Ns = Ns Ar time Oc Oo Cm min_uses Ns = Ns Ar N Oc Oo Cm valid Ns = Ns Ar time Oc
.It Ic open_log_file_cache Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines a cache that stores the file descriptors of frequently used logs whose
names contain variables.
The directive has the following parameters:
.Bl -tag -width Ds
.It Cm max
sets the maximum number of descriptors in a cache; if the cache becomes full the
least recently used (LRU) descriptors are closed
.It Cm inactive
sets the time after which the cached descriptor is closed if there were no
access during this time; by default, 10 seconds
.It Cm min_uses
sets the minimum number of file uses during the time defined by the
.Cm inactive
parameter to let the descriptor stay open in a cache; by default, 1
.It Cm valid
sets the time after which it should be checked that the file still exists with
the same name; by default, 60 seconds
.It Cm off
disables caching
.El
.Pp
Usage example:
.Bd -literal -offset indent
open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;
.Ed
.El
.Ss Module ngx_http_map_module
.Bl -tag -width Ds
.It Ic map Ar string Ar $variable Brq No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
Creates a new variable whose value depends on values of one or more of the
source variables specified in the first parameter.
Before version 0.9.0 only a single variable could be specified in the first
parameter.
Since variables are evaluated only when they are used, the mere declaration even
of a large number of
.Ic map
variables does not add any extra costs to request processing.
Parameters inside the
.Ic map
block specify a mapping between source and resulting values.
Source values are specified as strings or regular expressions (0.9.6).
A regular expression should either start from the
.Qq ~
symbol for a case-sensitive matching, or from the
.Qq ~*
symbols (1.0.4) for case-insensitive matching.
A regular expression can contain named and positional captures that can later be
used in other directives along with the resulting variable.
If a source value matches one of the names of special parameters described
below, it should be prefixed with the \\ symbol.
The resulting value can be a string or another variable (0.9.0).
The directive also supports three special parameters:
.Bl -tag -width Ds
.It Cm default Ar value
sets the resulting value if the source value matches none of the specified
variants.
When
.Cm default
is not specified, the default resulting value will be an empty string.
.It Cm hostnames
indicates that source values can be hostnames with a prefix or suffix mask:
.Bd -literal -offset indent
*.example.com 1;
example.* 1;
.Ed
.Pp
The following two records
.Bd -literal -offset indent
example.com 1;
*.example.com 1;
.Ed
.Pp
can be combined:
.Bd -literal -offset indent
.example.com 1;
.Ed
.Pp
This parameter should be specified before the list of values.
.It Cm include Ar file
includes a file with values.
There can be several inclusions.
.El
.Pp
If the source value matches more than one of the specified variants, e.g. both a
mask and a regular expression match, the first matching variant will be chosen,
in the following order of priority:
.Bl -bullet
.It
string value without a mask
.It
longest string value with a prefix mask, e.g.
.Qq *.example.com
.It
longest string value with a suffix mask, e.g.
.Qq mail.*
.It
first matching regular expression (in order of appearance in a configuration
file)
.It
default value
.El
.It Ic map_hash_bucket_size Ar size
.Bl -tag -width Ds -compact
.It default: 32 | 64 | 128
.It context: Ic http
.El
.Pp
Sets the bucket size for the
.Ic map
variables hash tables.
Default value depends on the processor's cache line size.
The details of setting up hash tables are provided in a separate document.
.It Ic map_hash_max_size Ar size
.Bl -tag -width Ds -compact
.It default: 2048
.It context: Ic http
.El
.Pp
Sets the maximum
.Ar size
of the
.Ic map
variables hash tables.
The details of setting up hash tables are provided in a separate document.
.El
.Ss Module ngx_http_memcached_module
.Bl -tag -width Ds
.It Ic memcached_bind Ar address | Cm off
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Makes outgoing connections to a memcached server originate from the specified
local IP
.Ar address.
Parameter value can contain variables (1.3.12).
The special value
.Cm off
(1.3.12) cancels the effect of the
.Ic memcached_bind
directive inherited from the previous configuration level, which allows the
system to auto-assign the local IP address.
.It Ic memcached_buffer_size Ar size
.Bl -tag -width Ds -compact
.It default: 4k | 8k
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the
.Ar size
of the buffer used for reading a response received from the memcached server.
A response is passed to a client synchronously, as soon as it is received.
.It Ic memcached_connect_timeout Ar time
.Bl -tag -width Ds -compact
.It default: 60s
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines a timeout for establishing a connection with a memcached server.
It should be noted that this timeout cannot usually exceed 75 seconds.
.It Ic memcached_gzip_flag Ar flag
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables the test for the
.Ar flag
presence in the memcached server response and sets the
Content-Encoding
response header field to
.Ic gzip
if the flag is set.
.It Ic memcached_next_upstream Cm error | Cm timeout | Cm invalid_response | Cm not_found | Cm off No ...
.Bl -tag -width Ds -compact
.It default: Cm error Cm timeout
.It context: Ic http , Ic server , Ic location
.El
.Pp
Specifies in which cases a request should be passed to the next server:
.Bl -tag -width Ds
.It Cm error
an error occurred while establishing a connection with the server, passing a
request to it, or reading the response header;
.It Cm timeout
a timeout has occurred while establishing a connection with the server, passing
a request to it, or reading the response header;
.It Cm invalid_response
a server returned an empty or invalid response;
.It Cm not_found
a response was not found on the server;
.It Cm off
disables passing a request to the next server.
.El
.Pp
One should bear in mind that passing a request to the next server is only
possible if nothing has been sent to a client yet.
That is, if an error or timeout occurs in the middle of the transferring of a
response, fixing this is impossible.
The directive also defines what is considered an unsuccessful attempt of
communication with a
.Ic server.
The cases of
.Cm error ,
.Cm timeout
and
.Cm invalid_header
are always considered unsuccessful attempts, even if they are not specified in
the directive.
The case of
.Cm not_found
is never considered an unsuccessful attempt.
.It Ic memcached_pass Ar address
.Bl -tag -width Ds -compact
.It default:
.It context: Ic location , Ic if in location
.El
.Pp
Sets the memcached server address.
The address can be specified as a domain name or an address, and a port:
.Bd -literal -offset indent
memcached_pass localhost:11211;
.Ed
.Pp
or as a UNIX-domain socket path:
.Bd -literal -offset indent
memcached_pass unix:/tmp/memcached.socket;
.Ed
.Pp
If a domain name resolves to several addresses, all of them will be used in a
round-robin fashion.
In addition, an address can be specified as a server group.
.It Ic memcached_read_timeout Ar time
.Bl -tag -width Ds -compact
.It default: 60s
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines a timeout for reading a response from the memcached server.
A timeout is set only between two successive read operations, not for the
transmission of the whole response.
If a memcached server does not transmit anything within this time, the
connection is closed.
.It Ic memcached_send_timeout Ar time
.Bl -tag -width Ds -compact
.It default: 60s
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets a timeout for transmitting a request to the memcached server.
A timeout is set only between two successive write operations, not for the
transmission of the whole request.
If a memcached server does not receive anything within this time, a connection
is closed.
.El
.Ss Module ngx_http_mp4_module
.Em This module is not enabled on OpenBSD.
.Bl -tag -width Ds
.It Ic mp4
.Bl -tag -width Ds -compact
.It default:
.It context: Ic location
.El
.Pp
Turns on module processing in a surrounding location.
.It Ic mp4_buffer_size Ar size
.Bl -tag -width Ds -compact
.It default: 512K
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the initial size of a memory buffer used for processing MP4 files.
.It Ic mp4_max_buffer_size Ar size
.Bl -tag -width Ds -compact
.It default: 10M
.It context: Ic http , Ic server , Ic location
.El
.Pp
During metadata processing, a larger buffer may become necessary.
Its size cannot exceed the specified
.Ar size ,
or else nginx will return the 500 (Internal Server Error) server error, and
log the following message:
.Bd -literal -offset indent
"/some/movie/file.mp4" mp4 moov atom is too large:
12583268, you may want to increase mp4_max_buffer_size
.Ed
.It Ic mp4_limit_rate Cm on | Cm off | Ar factor
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
.Em This directive is only available in the commercial version of nginx.
.Pp
Enables or disables rate limiting based on the average bitrate of the MP4 file
served.
To calculate the rate, the bitrate is multiplied by the specified
.Ar factor.
The special value
.Cm on
corresponds to the factor of 1.1.
.It Ic mp4_limit_rate_after Ar time
.Bl -tag -width Ds -compact
.It default: 1m
.It context: Ic http , Ic server , Ic location
.El
.Pp
.Em This directive is only available in the commercial version of nginx.
.Pp
Limits the rate after sending the specified amount of media data.
.El
.Ss Module ngx_http_perl_module
.Em This module is not enabled on OpenBSD.
.Bl -tag -width Ds
.It Ic perl Ar module Ns :: Ns Ar function | 'sub { ... }'
.Bl -tag -width Ds -compact
.It default:
.It context: Ic location , Ic limit_except
.El
.Pp
Sets a Perl handler for the given location.
.It Ic perl_modules Ar path
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
Sets an additional path for Perl modules.
.It Ic perl_require Ar module
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
Defines the name of a module that will be loaded during each reconfiguration.
Several
.Ic perl_require
directives can be present.
.It Ic perl_set Ar $variable Ar module Ns :: Ns Ar function | 'sub { ... }'
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
Installs a Perl handler for the specified variable.
.El
.Ss Module ngx_http_proxy_module
.Bl -tag -width Ds
.It Ic proxy_bind Ar address | Cm off
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Makes outgoing connections to a proxied server originate from the specified
local IP
.Ar address.
Parameter value can contain variables (1.3.12).
The special value
.Cm off
(1.3.12) cancels the effect of the
.Ic proxy_bind
directive inherited from the previous configuration level, which allows the
system to auto-assign the local IP address.
.It Ic proxy_buffer_size Ar size
.Bl -tag -width Ds -compact
.It default: 4k | 8k
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the
.Ar size
of the buffer used for reading the first part of a response received from the
proxied server.
This part usually contains a small response header.
By default, the buffer size is equal to the size of one buffer set by the
.Ic proxy_buffers
directive.
It can be made smaller however.
.It Ic proxy_buffering Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables buffering of responses from the proxied server.
When buffering is enabled, nginx receives a response from the proxied server as
soon as possible, saving it into the buffers set by the
.Ic proxy_buffer_size
and
.Ic proxy_buffers
directives.
If the whole response does not fit into memory, a part of it can be saved to a
.Ic proxy_temp_path
temporary file
on the disk.
Writing to temporary files is controlled by the
.Ic proxy_max_temp_file_size
and
.Ic proxy_temp_file_write_size
directives.
When buffering is disabled, a response is passed to a client synchronously,
immediately as it is received.
nginx will not try to read the whole response from the proxied server.
The maximum size of the data that nginx can receive from the server at a time is
set by the
.Ic proxy_buffer_size
directive.
Buffering can also be enabled or disabled by passing
.Cm yes
or
.Cm no
in the X-Accel-Buffering response header field.
This capability can be disabled using the
.Ic proxy_ignore_headers
directive.
.It Ic proxy_buffers Ar number Ar size
.Bl -tag -width Ds -compact
.It default: 8 4k | 8k
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the
.Ar number
and
.Ar size
of buffers used for reading a response from the proxied server, for a single
connection.
By default, the buffer size is equal to one memory page.
This is either 4K or 8K, depending on a platform.
.It Ic proxy_busy_buffers_size Ar size
.Bl -tag -width Ds -compact
.It default: 8k | 16k
.It context: Ic http , Ic server , Ic location
.El
.Pp
When buffering of responses from the proxied server is enabled, limits the total
.Ar size
of buffers that can be busy sending a response to the client while the response
is not yet fully read.
In the mean time, the rest of the buffers can be used for reading a response
and, if needed, buffering part of a response to a temporary file.
By default,
.Ar size
is limited by the size of two buffers set by the
.Ic proxy_buffer_size
and
.Ic proxy_buffers
directives.
.It Ic proxy_cache Ar zone | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines a shared memory zone used for caching.
The same zone can be used in several places.
The
.Cm off
parameter disables caching inherited from the previous configuration level.
.It Ic proxy_cache_bypass Ar string No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines conditions under which the response will not be taken from a cache.
If at least one value of the string parameters is not empty and is not equal to
0 then the response will not be taken from the cache:
.Bd -literal -offset indent
proxy_cache_bypass $cookie_nocache $arg_nocache$arg_comment;
proxy_cache_bypass $http_pragma $http_authorization;
.Ed
.Pp
Can be used along with the
.Ic proxy_no_cache
directive.
.It Ic proxy_cache_key Ar string
.Bl -tag -width Ds -compact
.It default: $scheme$proxy_host$request_uri
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines a key for caching, for example
.Bd -literal -offset indent
proxy_cache_key "$host$request_uri $cookie_user";
.Ed
.Pp
By default, the directive's value is close to the string
.Bd -literal -offset indent
proxy_cache_key $scheme$proxy_host$uri$is_args$args;
.Ed
.It Ic proxy_cache_lock Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
When enabled, only one request at a time will be allowed to populate a new cache
element identified according to the
.Ic proxy_cache_key
directive by passing a request to a proxied server.
Other requests of the same cache element will either wait for a response to
appear in the cache or the cache lock for this element to be released, up to the
time set by the
.Ic proxy_cache_lock_timeout
directive.
.It Ic proxy_cache_lock_timeout Ar time
.Bl -tag -width Ds -compact
.It default: 5s
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets a timeout for
.Ic proxy_cache_lock .
.It Ic proxy_cache_methods Cm GET | Cm HEAD | Cm POST No ...
.Bl -tag -width Ds -compact
.It default: Cm GET Cm HEAD
.It context: Ic http , Ic server , Ic location
.El
.Pp
If the client request method is listed in this directive then the response will
be cached.
.Cm GET
and
.Cm HEAD
methods are always added to the list, though it is recommended to specify them
explicitly.
See also the
.Ic proxy_no_cache
directive.
.It Ic proxy_cache_min_uses Ar number
.Bl -tag -width Ds -compact
.It default: 1
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the
.Ar number
of requests after which the response will be cached.
.It Ic proxy_cache_path Ar path Oo Cm levels Ns = Ns Ar levels Oc Cm keys_zone Ns = Ns Ar name Ns : Ns Ar size Oo Cm inactive Ns = Ns Ar time Oc Oo Cm max_size Ns = Ns Ar size Oc Oo Cm loader_files Ns = Ns Ar number Oc Oo Cm loader_sleep Ns = Ns Ar time Oc Oo Cm loader_threshold Ns = Ns Ar time Oc
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
Sets the path and other parameters of a cache.
Cache data are stored in files.
Both the key and file name in a cache are a result of applying the MD5 function
to the proxied URL.
The
.Ar levels
parameter defines hierarchy levels of a cache.
For example, in the following configuration
.Bd -literal -offset indent
proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=one:10m;
.Ed
.Pp
file names in a cache will look like this:
.Bd -literal -offset indent
/data/nginx/cache/c/29/b7f54b2df7773722d382f4809d65029c
.Ed
.Pp
A cached response is first written to a temporary file, and then the file is
renamed.
Starting from version 0.8.9, temporary files and the cache can be put on
different file systems.
However, be aware that in this case a file is copied across two file systems
instead of the cheap renaming operation.
It is thus recommended that for any given location both cache and a directory
holding temporary files, set by the
.Ic proxy_temp_path
directive, are put on the same file system.
In addition, all active keys and information about data are stored in a shared
memory zone, whose
.Ar name
and
.Ar size
are configured by the
.Cm keys_zone
parameter.
Cached data that are not accessed during the time specified by the
.Cm inactive
parameter get removed from the cache regardless of their freshness.
By default,
.Cm inactive
is set to 10 minutes.
The special cache manager process monitors the maximum cache size set by the
.Cm max_size
parameter.
When this size is exceeded, it removes the least recently used data.
A minute after the start the special cache loader process is activated.
It loads information about previously cached data stored on file system into a
cache zone.
The loading is done in iterations.
During one iteration no more than
.Cm loader_files
items are loaded (by default, 100).
Besides, the duration of one iteration is limited by the
.Cm loader_threshold
parameter (by default, 200 milliseconds).
Between iterations, a pause configured by the
.Cm loader_sleep
parameter (by default, 50 milliseconds) is made.
.It Ic proxy_cache_use_stale Cm error | Cm timeout | Cm invalid_header | Cm updating | Cm http_500 | Cm http_502 | Cm http_503 | Cm http_504 | Cm http_403 | Cm http_404 | Cm off No ...
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Determines in which cases a stale cached response can be used when an error
occurs during communication with the proxied server.
The directive's parameters match the parameters of the
.Ic proxy_next_upstream
directive.
Additionally, the
.Cm updating
parameter permits using a stale cached response if it is currently being
updated.
This allows minimizing the number of accesses to proxied servers when updating
cached data.
To minimize the number of accesses to proxied servers when populating a new
cache element, the
.Ic proxy_cache_lock
directive can be used.
.It Ic proxy_cache_valid Oo Ar code No ... Oc Ar time
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets caching time for different response codes.
For example, the following directives
.Bd -literal -offset indent
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
.Ed
.Pp
set 10 minutes of caching for responses with codes 200 and 302 and 1 minute for
responses with code 404.
If only caching
.Ar time
is specified
.Bd -literal -offset indent
proxy_cache_valid 5m;
.Ed
.Pp
then only 200, 301, and 302 responses are cached.
In addition, the
.Cm any
parameter can be specified to cache any responses:
.Bd -literal -offset indent
proxy_cache_valid 200 302 10m;
proxy_cache_valid 301 1h;
proxy_cache_valid any 1m;
.Ed
.Pp
Parameters of caching can also be set directly in the response header.
This has higher priority than setting of caching time using the directive.
The X-Accel-Expires header field sets caching time of a response in seconds.
The zero value disables caching for a response.
If a value starts with the
.Qq @
prefix, it sets an absolute time in seconds since Epoch, up to which the
response may be cached.
If header does not include the X-Accel-Expires field, parameters of caching may
be set in the header fields Expires or Cache-Control.
If a header includes the Set-Cookie field, such a response will not be cached.
Processing of one or more of these response header fields can be disabled using
the
.Ic proxy_ignore_headers
directive.
.It Ic proxy_connect_timeout Ar time
.Bl -tag -width Ds -compact
.It default: 60s
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines a timeout for establishing a connection with a proxied server.
It should be noted that this timeout cannot usually exceed 75 seconds.
.It Ic proxy_cookie_domain Cm off
.It Ic proxy_cookie_domain Ar domain Ar replacement
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets a text that should be changed in the
.Ar domain
attribute of the Set-Cookie header fields of a proxied server response.
Suppose a proxied server returned the Set-Cookie header field with the attribute
.Ar domain Ns = Ns localhost.
The directive
.Bd -literal -offset indent
proxy_cookie_domain localhost example.org;
.Ed
.Pp
will rewrite this attribute to
.Ar domain Ns = Ns example.org .
A dot at the beginning of the
.Ar domain
and
.Ar replacement
strings and the
.Ar domain
attribute is ignored.
Matching is case-insensitive.
The
.Ar domain
and
.Ar replacement
strings can contain variables:
.Bd -literal -offset indent
proxy_cookie_domain www.$host $host;
.Ed
.Pp
The directive can also be specified using regular expressions.
In this case,
.Ar domain
should start from the
.Qq ~
symbol.
A regular expression can contain named and positional captures, and
.Ar replacement
can reference them:
.Bd -literal -offset indent
proxy_cookie_domain ~\\.(?P<sl_domain>[-0-9a-z]+\\.[a-z]+)$ $sl_domain;
.Ed
.Pp
There could be several
.Ic proxy_cookie_domain
directives:
.Bd -literal -offset indent
proxy_cookie_domain localhost example.org;
proxy_cookie_domain ~\\.([a-z]+\\.[a-z]+)$ $1;
.Ed
.Pp
The
.Cm off
parameter cancels the effect of all
.Ic proxy_cookie_domain
directives on the current level:
.Bd -literal -offset indent
proxy_cookie_domain off;
proxy_cookie_domain localhost example.org;
proxy_cookie_domain www.example.org example.org;
.Ed
.It Ic proxy_cookie_path Cm off
.It Ic proxy_cookie_path Ar path Ar replacement
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets a text that should be changed in the
.Ar path
attribute of the Set-Cookie header fields of a proxied server response.
Suppose a proxied server returned the Set-Cookie header field with the attribute
.Ar path Ns = Ns /two/some/uri/.
The directive
.Bd -literal -offset indent
proxy_cookie_path /two/ /;
.Ed
.Pp
will rewrite this attribute to
.Ar path Ns = Ns /some/uri/ .
The
.Ar path
and
.Ar replacement
strings can contain variables:
.Bd -literal -offset indent
proxy_cookie_path $uri /some$uri;
.Ed
.Pp
The directive can also be specified using regular expressions.
In this case,
.Ar path
should either start from the
.Qq ~
symbol for a case-sensitive matching, or from the
.Qq ~*
symbols for case-insensitive matching.
A regular expression can contain named and positional captures, and
.Ar replacement
can reference them:
.Bd -literal -offset indent
proxy_cookie_path ~*^/user/([^/]+) /u/$1;
.Ed
.Pp
There could be several
.Ic proxy_cookie_path
directives:
.Bd -literal -offset indent
proxy_cookie_path /one/ /;
proxy_cookie_path / /two/;
.Ed
.Pp
The
.Cm off
parameter cancels the effect of all
.Ic proxy_cookie_path
directives on the current level:
.Bd -literal -offset indent
proxy_cookie_path off;
proxy_cookie_path /two/ /;
proxy_cookie_path ~*^/user/([^/]+) /u/$1;
.Ed
.It Ic proxy_headers_hash_bucket_size Ar size
.Bl -tag -width Ds -compact
.It default: 64
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the bucket
.Ar size
for hash tables used by the
.Ic proxy_hide_header
and
.Ic proxy_set_header
directives.
The details of setting up hash tables are provided in a separate document.
.It Ic proxy_headers_hash_max_size Ar size
.Bl -tag -width Ds -compact
.It default: 512
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the maximum
.Ar size
of hash tables used by the
.Ic proxy_hide_header
and
.Ic proxy_set_header
directives.
The details of setting up hash tables are provided in a separate document.
.It Ic proxy_hide_header Ar field
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
By default, nginx does not pass the header fields Date, Server, X-Pad and
X-Accel-... from the response of a proxied server to a client.
The
.Ic proxy_hide_header
directive sets additional fields that will not be passed.
If, on the contrary, the passing of fields needs to be permitted, the
.Ic proxy_pass_header
directive can be used.
.It Ic proxy_http_version Cm 1.0 | Cm 1.1
.Bl -tag -width Ds -compact
.It default: 1.0
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the HTTP protocol version for proxying.
By default, version 1.0 is used.
Version 1.1 is recommended for use with
.Ic keepalive
connections.
.It Ic proxy_ignore_client_abort Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Determines whether the connection with a proxied server should be closed when a
client closes a connection without waiting for a response.
.It Ic proxy_ignore_headers Ar field No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Disables processing of certain response header fields from the proxied server.
The following fields can be ignored: X-Accel-Redirect, X-Accel-Expires,
X-Accel-Limit-Rate (1.1.6), X-Accel-Buffering (1.1.6), X-Accel-Charset (1.1.6),
Expires, Cache-Control and Set-Cookie (0.8.44).
If not disabled, processing of these header fields has the following effect:
.Bl -bullet
.It
X-Accel-Expires, Expires, Cache-Control, and Set-Cookie set the parameters of
response
.Ic proxy_cache_valid
caching;
.It
X-Accel-Redirect performs an
.Ic internal
redirect
to the specified URI;
.It
X-Accel-Limit-Rate sets the
.Ic limit_rate
rate
limit
for transmission of a response to a client;
.It
X-Accel-Buffering enables or disables buffering of a response;
.It
X-Accel-Charset sets the desired
.Ic charset
of a response.
.El
.It Ic proxy_intercept_errors Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Determines whether proxied responses with codes greater than or equal to 300
should be passed to a client or be redirected to nginx for processing with the
.Ic error_page
directive.
.It Ic proxy_max_temp_file_size Ar size
.Bl -tag -width Ds -compact
.It default: 1024m
.It context: Ic http , Ic server , Ic location
.El
.Pp
When buffering of responses from the proxied server is enabled, and the whole
response does not fit into the memory buffers set by the
.Ic proxy_buffer_size
and
.Ic proxy_buffers
directives, a part of the response can be saved to a temporary file.
This directive sets the maximum
.Ar size
of a temporary file.
The size of data written to a temporary file at a time is set by the
.Ic proxy_temp_file_write_size
directive.
The zero value disables buffering of responses to temporary files.
.It Ic proxy_method Ar method
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Specifies the HTTP
.Ar method
to use in requests forwarded to the proxied server instead of the method from
the client request.
.It Ic proxy_next_upstream Cm error | Cm timeout | Cm invalid_header | Cm http_500 | Cm http_502 | Cm http_503 | Cm http_504 | Cm http_403 | Cm http_404 | Cm off No ...
.Bl -tag -width Ds -compact
.It default: Cm error Cm timeout
.It context: Ic http , Ic server , Ic location
.El
.Pp
Specifies in which cases a request should be passed to the next server:
.Bl -tag -width Ds
.It Cm error
an error occurred while establishing a connection with the server, passing a
request to it, or reading the response header;
.It Cm timeout
a timeout has occurred while establishing a connection with the server, passing
a request to it, or reading the response header;
.It Cm invalid_header
a server returned an empty or invalid response;
.It Cm http_500
a server returned a response with the code 500;
.It Cm http_502
a server returned a response with the code 502;
.It Cm http_503
a server returned a response with the code 503;
.It Cm http_504
a server returned a response with the code 504;
.It Cm http_403
a server returned a response with the code 403;
.It Cm http_404
a server returned a response with the code 404;
.It Cm off
disables passing a request to the next server.
.El
.Pp
One should bear in mind that passing a request to the next server is only
possible if nothing has been sent to a client yet.
That is, if an error or timeout occurs in the middle of the transferring of a
response, fixing this is impossible.
The directive also defines what is considered an unsuccessful attempt of
communication with a
.Ic server.
The cases of
.Cm error ,
.Cm timeout
and
.Cm invalid_header
are always considered unsuccessful attempts, even if they are not specified in
the directive.
The cases of
.Cm http_500 ,
.Cm http_502 ,
.Cm http_503
and
.Cm http_504
are considered unsuccessful attempts only if they are specified in the
directive.
The cases of
.Cm http_403
and
.Cm http_404
are never considered unsuccessful attempts.
.It Ic proxy_no_cache Ar string No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines conditions under which the response will not be saved to a cache.
If at least one value of the string parameters is not empty and is not equal to
0 then the response will not be saved:
.Bd -literal -offset indent
proxy_no_cache $cookie_nocache $arg_nocache$arg_comment;
proxy_no_cache $http_pragma $http_authorization;
.Ed
.Pp
Can be used along with the
.Ic proxy_cache_bypass
directive.
.It Ic proxy_pass Ar URL
.Bl -tag -width Ds -compact
.It default:
.It context: Ic location , Ic if in location , Ic limit_except
.El
.Pp
Sets the protocol and address of a proxied server and an optional URI to which a
location should be mapped.
As a protocol, http or https can be specified.
The address can be specified as a domain name or IP address, and an optional
port:
.Bd -literal -offset indent
proxy_pass http://localhost:8000/uri/;
.Ed
.Pp
or as a UNIX-domain socket path specified after the word
.Cm unix
and enclosed in colons:
.Bd -literal -offset indent
proxy_pass http://unix:/tmp/backend.socket:/uri/;
.Ed
.Pp
If a domain name resolves to several addresses, all of them will be used in a
round-robin fashion.
In addition, an address can be specified as a server group.
A request URI is passed to the server as follows:
.Bl -bullet
.It
If the
.Ic proxy_pass
directive is specified with a URI, then when a request is passed to the server,
the part of a
.Ic location
normalized
request URI matching the location is replaced by a URI specified in the
directive:
.Bd -literal -offset indent
location /name/ {
proxy_pass http://127.0.0.1/remote/;
}
.Ed
.It
If
.Ic proxy_pass
is specified without a URI, the request URI is passed to the server in the same
form as sent by a client when the original request is processed, or the full
normalized request URI is passed when processing the changed URI:
.Bd -literal -offset indent
location /some/path/ {
proxy_pass http://127.0.0.1;
}
.Ed
.Pp
Before version 1.1.12, if
.Ic proxy_pass
is specified without a URI, the original request URI might be passed instead of
the changed URI in some cases.
.El
.Pp
In some cases, the part of a request URI to be replaced cannot be determined:
.Bl -bullet
.It
When location is specified using a regular expression.
In this case, the directive should be specified without a URI.
.It
When the URI is changed inside a proxied location using the
.Ic rewrite
directive, and this same configuration will be used to process a request
.Pq Ic break :
.Bd -literal -offset indent
location /name/ {
rewrite /name/([^/]+) /users?name=$1 break;
proxy_pass http://127.0.0.1;
}
.Ed
.Pp
In this case, the URI specified in the directive is ignored and the full changed
request URI is passed to the server.
.El
.Pp
A server name, its port and the passed URI can also be specified using
variables:
.Bd -literal -offset indent
proxy_pass http://$host$uri;
.Ed
.Pp
or even like this:
.Bd -literal -offset indent
proxy_pass $request;
.Ed
.Pp
In this case, the server name is searched among the described server groups,
and, if not found, is determined using a
.Ic resolver .
WebSocket
proxying requires special configuration and is supported since version 1.3.13.
.It Ic proxy_pass_header Ar field
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Permits passing
.Ic proxy_hide_header
otherwise disabled
header fields from a proxied server to a client.
.It Ic proxy_read_timeout Ar time
.Bl -tag -width Ds -compact
.It default: 60s
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines a timeout for reading a response from the proxied server.
A timeout is set only between two successive read operations, not for the
transmission of the whole response.
If a proxied server does not transmit anything within this time, a connection is
closed.
.It Ic proxy_pass_request_body Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server , Ic location
.El
.Pp
Indicates whether the original request body is passed to the proxied server.
.Bd -literal -offset indent
location /x-accel-redirect-here/ {
proxy_method GET;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_pass ...
}
.Ed
.Pp
See also the
.Ic proxy_set_header
and
.Ic proxy_pass_request_headers
directives.
.It Ic proxy_pass_request_headers Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server , Ic location
.El
.Pp
Indicates whether the header fields of the original request are passed to the
proxied server.
.Bd -literal -offset indent
location /x-accel-redirect-here/ {
proxy_method GET;
proxy_pass_request_headers off;
proxy_pass_request_body off;
proxy_pass ...
}
.Ed
.Pp
See also the
.Ic proxy_set_header
and
.Ic proxy_pass_request_body
directives.
.It Ic proxy_redirect Cm default
.It Ic proxy_redirect Cm off
.It Ic proxy_redirect Ar redirect Ar replacement
.Bl -tag -width Ds -compact
.It default: Cm default
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the text that should be changed in the Location and Refresh header fields
of a proxied server response.
Suppose a proxied server returned the header field
.Qq Location: http://localhost:8000/two/some/uri/ .
The directive
.Bd -literal -offset indent
proxy_redirect http://localhost:8000/two/ http://frontend/one/;
.Ed
.Pp
will rewrite this string to
.Qq Location: http://frontend/one/some/uri/ .
A server name may be omitted in the
.Ar replacement
string:
.Bd -literal -offset indent
proxy_redirect http://localhost:8000/two/ /;
.Ed
.Pp
then the primary server's name and port, if different from 80, will be inserted.
The default replacement specified by the
.Cm default
parameter uses the parameters of the
.Ic location
and
.Ic proxy_pass
directives.
Hence, the two configurations below are equivalent:
.Bd -literal -offset indent
location /one/ {
proxy_pass http://upstream:port/two/;
proxy_redirect default;
.Ed
.Bd -literal -offset indent
location /one/ {
proxy_pass http://upstream:port/two/;
proxy_redirect http://upstream:port/two/ /one/;
.Ed
.Pp
The
.Cm default
parameter is not permitted if
.Ic proxy_pass
is specified using variables.
A
.Ar replacement
string can contain variables:
.Bd -literal -offset indent
proxy_redirect http://localhost:8000/ http://$host:$server_port/;
.Ed
.Pp
A
.Ar redirect
can also contain (1.1.11) variables:
.Bd -literal -offset indent
proxy_redirect http://$proxy_host:8000/ /;
.Ed
.Pp
The directive can be specified (1.1.11) using regular expressions.
In this case,
.Ar redirect
should either start with the
.Qq ~
symbol for a case-sensitive matching, or with the
.Qq ~*
symbols for case-insensitive matching.
A regular expression can contain named and positional captures, and
.Ar replacement
can reference them:
.Bd -literal -offset indent
proxy_redirect ~^(http://[^:]+):\\d+(/.+)$ $1$2;
proxy_redirect ~*/user/([^/]+)/(.+)$ http://$1.example.com/$2;
.Ed
.Pp
There could be several
.Ic proxy_redirect
directives:
.Bd -literal -offset indent
proxy_redirect default;
proxy_redirect http://localhost:8000/ /;
proxy_redirect http://www.example.com/ /;
.Ed
.Pp
The
.Cm off
parameter cancels the effect of all
.Ic proxy_redirect
directives on the current level:
.Bd -literal -offset indent
proxy_redirect off;
proxy_redirect default;
proxy_redirect http://localhost:8000/ /;
proxy_redirect http://www.example.com/ /;
.Ed
.Pp
Using this directive, it is also possible to add host names to relative
redirects issued by a proxied server:
.Bd -literal -offset indent
proxy_redirect / /;
.Ed
.It Ic proxy_send_lowat Ar size
.Bl -tag -width Ds -compact
.It default: 0
.It context: Ic http , Ic server , Ic location
.El
.Pp
If the directive is set to a non-zero value, nginx will try to minimize the
number of send operations on outgoing connections to a proxied server by using
either
.Dv NOTE_LOWAT
flag of the
.Cm kqueue
method, or the
.Dv SO_SNDLOWAT
socket option, with the specified
.Ar size .
This directive is ignored on Linux, Solaris, and Windows.
.It Ic proxy_send_timeout Ar time
.Bl -tag -width Ds -compact
.It default: 60s
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets a timeout for transmitting a request to the proxied server.
A timeout is set only between two successive write operations, not for the
transmission of the whole request.
If a proxied server does not receive anything within this time, a connection is
closed.
.It Ic proxy_set_body Ar value
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Allows redefining the request body passed to the proxied server.
A
.Ar value
can contain text, variables, and their combination.
.It Ic proxy_set_header Ar field Ar value
.Bl -tag -width Ds -compact
.It default: Host $proxy_host
.It context: Ic http , Ic server , Ic location
.El
.Pp
Allows redefining or appending fields to the request header passed to the
proxied server.
A
.Ar value
can contain text, variables, and their combinations.
These directives are inherited from the previous level if and only if there are
no
.Ic proxy_set_header
directives defined on the current level.
By default, only two fields are redefined:
.Bd -literal -offset indent
proxy_set_header Host $proxy_host;
proxy_set_header Connection close;
.Ed
.Pp
An unchanged Host request header field can be passed like this:
.Bd -literal -offset indent
proxy_set_header Host $http_host;
.Ed
.Pp
However, if this field is not present in a client request header then nothing
will be passed.
In such a case it is better to use the
.Va $host
variable - its value equals the server name in the Host request header field or
the primary server name if this field is not present:
.Bd -literal -offset indent
proxy_set_header Host $host;
.Ed
.Pp
In addition, the server name can be passed together with the port of the proxied
server:
.Bd -literal -offset indent
proxy_set_header Host $host:$proxy_port;
.Ed
.Pp
If the value of a header field is an empty string then this field will not be
passed to a proxied server:
.Bd -literal -offset indent
proxy_set_header Accept-Encoding "";
.Ed
.It Ic proxy_ssl_ciphers Ar ciphers
.Bl -tag -width Ds -compact
.It default: Cm DEFAULT
.It context: Ic http , Ic server , Ic location
.El
.Pp
Specifies the enabled ciphers for requests to a proxied HTTPS server.
The ciphers are specified in the format understood by the OpenSSL library.
The full list can be viewed using the
.Ic openssl ciphers
command.
.It Ic proxy_ssl_session_reuse Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server , Ic location
.El
.Pp
Determines whether SSL sessions can be reused when working with the proxied
server.
If the errors
SSL3_GET_FINISHED:digest check failed
appear in the logs, try disabling session reuse.
.It Ic proxy_ssl_protocols Oo Cm SSLv2 Oc Oo Cm SSLv3 Oc Oo Cm TLSv1 Oc Oo Cm TLSv1.1 Oc Oo Cm TLSv1.2 Oc
.Bl -tag -width Ds -compact
.It default: SSLv3 TLSv1 TLSv1.1 TLSv1.2
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables the specified protocols for requests to a proxied HTTPS server.
.It Ic proxy_store Cm on | Cm off | Ar string
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables saving of files to a disk.
The
.Cm on
parameter saves files with paths corresponding to the directives
.Ic alias
or
.Ic root.
The
.Cm off
parameter disables saving of files.
In addition, the file name can be set explicitly using the
.Ar string
with variables:
.Bd -literal -offset indent
proxy_store /data/www$original_uri;
.Ed
.Pp
The modification time of files is set according to the received Last-Modified
response header field.
A response is first written to a temporary file, and then the file is renamed.
Starting from version 0.8.9, temporary files and the persistent store can be put
on different file systems.
However, be aware that in this case a file is copied across two file systems
instead of the cheap renaming operation.
It is thus recommended that for any given location both saved files and a
directory holding temporary files, set by the
.Ic proxy_temp_path
directive, are put on the same file system.
This directive can be used to create local copies of static unchangeable files,
e.g.:
.Bd -literal -offset indent
location /images/ {
root /data/www;
open_file_cache_errors off;
error_page 404 = /fetch$uri;
}
location /fetch/ {
internal;
proxy_pass http://backend/;
proxy_store on;
proxy_store_access user:rw group:rw all:r;
proxy_temp_path /data/temp;
alias /data/www/;
}
.Ed
.Pp
or like this:
.Bd -literal -offset indent
location /images/ {
root /data/www;
error_page 404 = @fetch;
}
location @fetch {
internal;
proxy_pass http://backend;
proxy_store on;
proxy_store_access user:rw group:rw all:r;
proxy_temp_path /data/temp;
root /data/www;
}
.Ed
.It Ic proxy_store_access Ar users Ns : Ns Ar permissions No ...
.Bl -tag -width Ds -compact
.It default: user:rw
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets access permissions for newly created files and directories, e.g.:
.Bd -literal -offset indent
proxy_store_access user:rw group:rw all:r;
.Ed
.Pp
If any
.Ar group
or
.Cm all
access permissions are specified then
.Ar user
permissions may be omitted:
.Bd -literal -offset indent
proxy_store_access group:rw all:r;
.Ed
.It Ic proxy_temp_file_write_size Ar size
.Bl -tag -width Ds -compact
.It default: 8k | 16k
.It context: Ic http , Ic server , Ic location
.El
.Pp
Limits the
.Ar size
of data written to a temporary file at a time, when buffering of responses from
the proxied server to temporary files is enabled.
By default,
.Ar size
is limited by two buffers set by the
.Ic proxy_buffer_size
and
.Ic proxy_buffers
directives.
The maximum size of a temporary file is set by the
.Ic proxy_max_temp_file_size
directive.
.It Ic proxy_temp_path Ar path Oo Ar level1 Oo Ar level2 Oo Ar level3 Oc Oc Oc
.Bl -tag -width Ds -compact
.It default: proxy_temp
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines a directory for storing temporary files with data received from proxied
servers.
Up to three-level subdirectory hierarchy can be used underneath the specified
directory.
For example, in the following configuration
.Bd -literal -offset indent
proxy_temp_path /spool/nginx/proxy_temp 1 2;
.Ed
.Pp
a temporary file might look like this:
.Bd -literal -offset indent
/spool/nginx/proxy_temp/7/45/00000123457
.Ed
.El
.Ss Module ngx_http_random_index_module
.Em This module is not enabled on OpenBSD.
.Bl -tag -width Ds
.It Ic random_index Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic location
.El
.Pp
Enables or disables module processing in a surrounding location.
.El
.Ss Module ngx_http_realip_module
.Em This module is not enabled on OpenBSD.
.Bl -tag -width Ds
.It Ic set_real_ip_from Ar address | Ar CIDR | Cm unix:
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines trusted addresses that are known to send correct replacement addresses.
If the special value
.Cm unix:
is specified, all UNIX-domain sockets will be trusted.
IPv6 addresses are supported starting from versions 1.3.0 and 1.2.1.
.It Ic real_ip_header Ar field | Cm X-Real-IP | Cm X-Forwarded-For
.Bl -tag -width Ds -compact
.It default: X-Real-IP
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines a request header field used to send the address for a replacement.
.It Ic real_ip_recursive Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
If recursive search is disabled, the original client address that matches one of
the trusted addresses is replaced by the last address sent in the request header
field defined by the
.Ic real_ip_header
directive.
If recursive search is enabled, the original client address that matches one of
the trusted addresses is replaced by the last non-trusted address sent in the
request header field.
.El
.Ss Module ngx_http_referer_module
.Bl -tag -width Ds
.It Ic referer_hash_bucket_size Ar size
.Bl -tag -width Ds -compact
.It default: 64
.It context: Ic server , Ic location
.El
.Pp
Sets the bucket size for the valid referers hash tables.
The details of setting up hash tables are provided in a separate document.
.It Ic referer_hash_max_size Ar size
.Bl -tag -width Ds -compact
.It default: 2048
.It context: Ic server , Ic location
.El
.Pp
Sets the maximum
.Ar size
of the valid referers hash tables.
The details of setting up hash tables are provided in a separate document.
.It Ic valid_referers Cm none | Cm blocked | Cm server_names | Ar string No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic server , Ic location
.El
.Pp
Specifies the Referer request header field values that will cause the embedded
.Va $invalid_referer
variable to be set to an empty string.
Otherwise, the variable will be set to
1.
Search for a match is case-insensitive.
Parameters can be as follows:
.Bl -tag -width Ds
.It Cm none
the Referer field is missing in the request header;
.It Cm blocked
the Referer field is present in the request header, but its value has been
deleted by a firewall or proxy server; such values are strings that do not start
with
.Qq http://
or
.Qq https:// ;
.It Cm server_names
the Referer request header field contains one of the server names;
.It Ar arbitrary string
defines a server name and an optional URI prefix.
A server name can have an
.Qq *
at the beginning or end.
During the checking, the server's port in the Referer field is ignored;
.It Ar regular expression
the first symbol should be a
.Qq ~.
It should be noted that an expression will be matched against the text starting
after the
.Qq http://
or
.Qq https:// .
.El
.Pp
Example:
.Bd -literal -offset indent
valid_referers none blocked server_names
*.example.com example.* www.example.org/galleries/
~\\.google\\.;
.Ed
.El
.Ss Module ngx_http_rewrite_module
.Bl -tag -width Ds
.It Ic break
.Bl -tag -width Ds -compact
.It default:
.It context: Ic server , Ic location , Ic if
.El
.Pp
Stops processing the current set of
.Sx Module ngx_http_rewrite_module
directives.
Example:
.Bd -literal -offset indent
if ($slow) {
limit_rate 10k;
break;
}
.Ed
.It Ic if Po Ar condition Pc Brq No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic server , Ic location
.El
.Pp
The specified
.Ar condition
is evaluated.
If true, this module directives specified inside the braces are executed, and
the request is assigned the configuration inside the
.Ic if
directive.
Configurations inside the
.Ic if
directives are inherited from the previous configuration level.
A condition may be any of the following:
.Bl -bullet
.It
a variable name; false if the value of a variable is an empty string or 0;
Before version 1.0.1, any string starting with 0
was considered a false value.
.It
comparison of a variable with a string using the
.Qq =
and
.Qq !=
operators;
.It
matching of a variable against a regular expression using the
.Qq ~
(for case-sensitive matching) and
.Qq ~*
(for case-insensitive matching) operators.
Regular expressions can contain captures that are made available for later reuse
in the
.Va $1 No .. Va $9
variables.
Negative operators
.Qq !~
and
.Qq !~*
are also available.
If a regular expression includes the
.Qq }
or
.Qo ; Qc
characters, the whole expressions should be enclosed in single or double quotes.
.It
checking of a file existence with the
.Fl f
and
.Ic !-f
operators;
.It
checking of a directory existence with the
.Fl d
and
.Ic !-d
operators;
.It
checking of a file, directory, or symbolic link existence with the
.Fl e
and
.Ic !-e
operators;
.It
checking for an executable file with the
.Fl x
and
.Ic !-x
operators.
.El
.Pp
Examples:
.Bd -literal -offset indent
if ($http_user_agent ~ MSIE) {
rewrite ^(.*)$ /msie/$1 break;
}
if ($http_cookie ~* "id=([^;]+)(?:; |$)") {
set $id $1;
}
if ($request_method = POST) {
return 405;
}
if ($slow) {
limit_rate 10k;
}
if ($invalid_referer) {
return 403;
}
.Ed
.Pp
A value of the
.Va $invalid_referer
embedded variable is set by the
.Ic valid_referers
directive.
.It Ic return Ar code Oo Ar text Oc
.It Ic return Ar code Ar URL
.It Ic return Ar URL
.Bl -tag -width Ds -compact
.It default:
.It context: Ic server , Ic location , Ic if
.El
.Pp
Stops processing and returns the specified
.Ar code
to a client.
The non-standard code 444 closes a connection without sending a response header.
Starting from version 0.8.42, it is possible to specify either a redirect URL
(for codes 301, 302, 303, and 307), or the response body
.Ar text
(for other codes).
A response body text and redirect URL can contain variables.
As a special case, a redirect URL can be specified as a URI local to this
server, in which case the full redirect URL is formed according to the request
scheme
.Pq Va $scheme
and the
.Ic server_name_in_redirect
and
.Ic port_in_redirect
directives.
In addition, a
.Ar URL
for temporary redirect with the code 302 can be specified as the sole parameter.
Such a parameter should start with the
.Qq http:// ,
.Qq https:// ,
or
.Ic $scheme
string.
A
.Ar URL
can contain variables.
Only the following codes could be returned before version 0.7.51: 204, 400,
402 - 406, 408, 410, 411, 413, 416, and 500 - 504.
The code 307 was not treated as a redirect until versions 1.1.16 and 1.0.13.
.It Ic rewrite Ar regex Ar replacement Oo Ar flag Oc
.Bl -tag -width Ds -compact
.It default:
.It context: Ic server , Ic location , Ic if
.El
.Pp
If the specified regular expression matches a URI, the URI is changed as
specified in the
.Ar replacement
string.
The
.Ic rewrite
directives are executed sequentially in order of their appearance in the
configuration file.
It is possible to terminate further processing of the directives using flags.
If a replacement string starts with
.Qq http://
or
.Qq https:// ,
the processing stops and the redirect is returned to a client.
An optional
.Ar flag
parameter can be one of:
.Bl -tag -width Ds
.It Cm last
stops processing the current set of
.Sx Module ngx_http_rewrite_module
directives and starts a search for a new location matching the changed URI;
.It Cm break
stops processing the current set of
.Sx Module ngx_http_rewrite_module
directives;
.It Cm redirect
returns a temporary redirect with the 302 code; used if a replacement string
does not start with
.Qq http://
or
.Qq https:// ;
.It Cm permanent
returns a permanent redirect with the 301 code.
.El
.Pp
The full redirect URL is formed according to the request scheme
.Pq Va $scheme
and the
.Ic server_name_in_redirect
and
.Ic port_in_redirect
directives.
Example:
.Bd -literal -offset indent
server {
...
rewrite ^(/download/.*)/media/(.*)\\..*$ $1/mp3/$2.mp3 last;
rewrite ^(/download/.*)/audio/(.*)\\..*$ $1/mp3/$2.ra last;
return 403;
...
}
.Ed
.Pp
But if these directives are put inside the
.Qq /download/
location, the
.Cm last
flag should be replaced by
.Ic break ,
or otherwise nginx will make 10 cycles and return the 500 error:
.Bd -literal -offset indent
location /download/ {
rewrite ^(/download/.*)/media/(.*)\\..*$ $1/mp3/$2.mp3 break;
rewrite ^(/download/.*)/audio/(.*)\\..*$ $1/mp3/$2.ra break;
return 403;
}
.Ed
.Pp
If a
.Ar replacement
string includes the new request arguments, the previous request arguments are
appended after them.
If this is undesired, putting a question mark at the end of a replacement string
avoids having them appended, for example:
.Bd -literal -offset indent
rewrite ^/users/(.*)$ /show?user=$1? last;
.Ed
.Pp
If a regular expression includes the
.Qq }
or
.Qo ; Qc
characters, the whole expressions should be enclosed in single or double quotes.
.It Ic rewrite_log Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location , Ic if
.El
.Pp
Enables or disables logging of
.Sx Module ngx_http_rewrite_module
module directives processing results into the
.Ic error_log
at the
.Cm notice
level.
.It Ic set Ar variable Ar value
.Bl -tag -width Ds -compact
.It default:
.It context: Ic server , Ic location , Ic if
.El
.Pp
Sets a
.Ar value
for the specified
.Ar variable.
A
.Ar value
can contain text, variables, and their combination.
.It Ic uninitialized_variable_warn Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server , Ic location , Ic if
.El
.Pp
Controls whether warnings about uninitialized variables are logged.
.El
.Ss Module ngx_http_secure_link_module
.Em This module is not enabled on OpenBSD.
.Bl -tag -width Ds
.It Ic secure_link Ar expression
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines a string with variables from which the checksum value and lifetime of a
link will be extracted.
Variables used in an
.Ar expression
are usually associated with a request; see
.Ic secure_link_md5
example
below.
The checksum value extracted from the string is compared with the MD5 hash value
of the expression defined by the
.Ic secure_link_md5
directive.
If the checksums are different, the
.Va $secure_link
variable is set to an empty string.
If the checksums are the same, the link lifetime is checked.
If the link has a limited lifetime and the time has expired, the
.Va $secure_link
variable is set to
0.
Otherwise, it is set to
1.
The MD5 hash value passed in a request is encoded in base64url.
If a link has a limited lifetime, the expiration time is set in seconds since
Epoch (Thu, 01 Jan 1970 00:00:00 GMT).
The value is specified in the expression after the MD5 hash, and is separated by
a comma.
The expiration time passed in a request is available through the
.Va $secure_link_expires
variable for a use in the
.Ic secure_link_md5
directive.
If the expiration time is not specified, a link has the unlimited lifetime.
.It Ic secure_link_md5 Ar expression
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines an expression for which the MD5 hash value will be computed and compared
with the value passed in a request.
The expression should contain the secured part of a link (resource) and a secret
ingredient.
If the link has a limited lifetime, the expression should also contain
.Va $secure_link_expires .
To prevent unauthorized access, the expression may contain some information
about the client, such as its address and browser version.
Example:
.Bd -literal -offset indent
location /s/ {
secure_link $arg_md5,$arg_expires;
secure_link_md5 "$secure_link_expires$uri$remote_addr secret";
if ($secure_link = "") {
return 403;
}
if ($secure_link = "0") {
return 410;
}
...
}
.Ed
.Pp
The
.Qq /s/link?md5 Ns = Ns _e4Nc3iduzkWRm01TBBNYw&expires Ns = Ns 2147483647
link restricts access to
.Qq /s/link
for the client with the IP address 127.0.0.1.
The link also has the limited lifetime until January 19, 2038 (GMT).
On UNIX, the
.Ar md5
request argument value can be obtained as:
.Bd -literal -offset indent
echo -n '2147483647/s/link127.0.0.1 secret' | \\
openssl md5 -binary | openssl base64 | tr +/ -_ | tr -d =
.Ed
.It Ic secure_link_secret Ar word
.Bl -tag -width Ds -compact
.It default:
.It context: Ic location
.El
.Pp
Defines a secret
.Ar word
used to check authenticity of requested links.
The full URI of a requested link looks as follows:
.Bd -literal -offset indent
/prefix/hash/link
.Ed
.Pp
where
.Ar hash
is a hexadecimal representation of the MD5 hash computed for the concatenation
of the link and secret word, and
.Ar prefix
is an arbitrary string without slashes.
If the requested link passes the authenticity check, the
.Va $secure_link
variable is set to the link extracted from the request URI.
Otherwise, the
.Va $secure_link
variable is set to an empty string.
Example:
.Bd -literal -offset indent
location /p/ {
secure_link_secret secret;
if ($secure_link = "") {
return 403;
}
rewrite ^ /secure/$secure_link;
}
location /secure/ {
internal;
}
.Ed
.Pp
A request of
.Qq /p/5e814704a28d9bc1914ff19fa0c4a00a/link
will be internally redirected to
.Qq /secure/link .
On UNIX, the hash value for this example can be obtained as:
.Bd -literal -offset indent
echo -n 'linksecret' | openssl md5 -hex
.Ed
.El
.Ss Module ngx_http_session_log_module
.Em This module is only available in the commercial version of nginx.
.Bl -tag -width Ds
.It Ic session_log_format Ar name Ar string No ...
.Bl -tag -width Ds -compact
.It default: combined Qq ...
.It context: Ic http
.El
.Pp
Specifies the output format of a log.
The value of the
.Va $body_bytes_sent
variable is aggregated across all requests in a session.
The values of all other variables available for logging correspond to the first
request in a session.
.It Ic session_log_zone Ar path Cm zone Ns = Ns Ar name Ns : Ns Ar size Oo Cm format Ns = Ns Ar format Oc Oo Cm timeout Ns = Ns Ar time Oc Oo Cm id Ns = Ns Ar id Oc Oo Cm md5 Ns = Ns Ar md5 Oc
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
Sets the path to a log file and configures the shared memory zone that is used
to store currently active sessions.
A session is considered active for as long as the time elapsed since the last
request in the session does not exceed the specified
.Cm timeout
(by default, 30 seconds).
Once a session is no longer active, it is written to the log.
The
.Ar id
parameter identifies the session to which a request is mapped.
The
.Ar id
parameter is set to the hexadecimal representation of an MD5 hash (for example,
obtained from a cookie using variables).
If this parameter is not specified or does not represent the valid MD5 hash,
nginx computes the MD5 hash from the value of the
.Ar md5
parameter and creates a new session using this hash.
Both the
.Ar id
and
.Ar md5
parameters can contain variables.
The
.Ar format
parameter sets the custom session log format configured by the
.Ic session_log_format
directive.
If
.Ar format
is not specified, the predefined
combined
format is used.
.It Ic session_log Ar name | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables the use of the specified session log.
The special value
.Cm off
cancels all
.Ic session_log
directives inherited from the previous configuration level.
.El
.Ss Module ngx_http_spdy_module
.Em This module is not enabled on OpenBSD.
.Bl -tag -width Ds
.It Ic spdy_headers_comp Ar level
.Bl -tag -width Ds -compact
.It default: 0
.It context: Ic http , Ic server
.El
.Pp
Sets the header compression
.Ar level
of a response in a range from 1 (fastest, less compression) to 9 (slowest, best
compression).
The special value 0 turns off the header compression.
.El
.Ss Module ngx_http_split_clients_module
.Bl -tag -width Ds
.It Ic split_clients Ar string Ar $variable Brq No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
Creates a variable for A/B testing, for example:
.Bd -literal -offset indent
split_clients "${remote_addr}AAA" $variant {
0.5% .one;
2.0% .two;
* "";
}
.Ed
.Pp
The value of the original string is hashed using MurmurHash2.
In the example given, hash values from 0 to 21474835 (0.5%) correspond to the
value
.Qq .one
of the
.Va $variant
variable, hash values from 21474836 to 107374180 (2%) correspond to the value
.Qq .two ,
and hash values from 107374181 to 4294967295 correspond to the value
.Qq
(an empty string).
.El
.Ss Module ngx_http_ssi_module
.Bl -tag -width Ds
.It Ic ssi Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location , Ic if in location
.El
.Pp
Enables or disables processing of SSI commands in responses.
.It Ic ssi_last_modified Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Allows preserving the Last-Modified header field from the original response
during SSI processing to facilitate response caching.
By default, the header field is removed as contents of the response are modified
during processing and may contain dynamically generated elements or parts that
are changed independently of the original response.
.It Ic ssi_min_file_chunk Cm size
.Bl -tag -width Ds -compact
.It default: 1k
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the minimum
.Ar size
for parts of a response stored on disk, starting from which it makes sense to
send them using
.Ic sendfile .
.It Ic ssi_silent_errors Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
If enabled, suppresses the output of the
.Qq an error occurred while processing the directive
string if an error occurred during SSI processing.
.It Ic ssi_types Ar mime-type No ...
.Bl -tag -width Ds -compact
.It default: text/html
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables processing of SSI commands in responses with the specified MIME types in
addition to text/html.
The special value
.Qq *
matches any MIME type (0.8.29).
.It Ic ssi_value_length Ar length
.Bl -tag -width Ds -compact
.It default: 256
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the maximum length of parameter values in SSI commands.
.El
.Ss Module ngx_http_ssl_module
.Bl -tag -width Ds
.It Ic ssl Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server
.El
.Pp
Enables the HTTPS protocol for the given virtual server.
It is recommended to use the
.Ar ssl
parameter of the
.Ic listen
directive instead of this directive.
.It Ic ssl_certificate Ar file
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server
.El
.Pp
Specifies a
.Ar file
with the certificate in the PEM format for the given virtual server.
If intermediate certificates should be specified in addition to a primary
certificate, they should be specified in the same file in the following order:
the primary certificate comes first, then the intermediate certificates.
A secret key in the PEM format may be placed in the same file.
It should be kept in mind that due to the HTTPS protocol limitations virtual
servers should listen on different IP addresses:
.Bd -literal -offset indent
server {
listen 192.168.1.1:443;
server_name one.example.com;
ssl_certificate /usr/local/nginx/conf/one.example.com.cert;
...
}
server {
listen 192.168.1.2:443;
server_name two.example.com;
ssl_certificate /usr/local/nginx/conf/two.example.com.cert;
...
}
.Ed
.Pp
otherwise the first server's certificate will be issued for the second site.
.It Ic ssl_certificate_key Ar file
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server
.El
.Pp
Specifies a
.Ar file
with the secret key in the PEM format for the given virtual server.
.It Ic ssl_ciphers Ar ciphers
.Bl -tag -width Ds -compact
.It default: HIGH:!aNULL:!MD5
.It context: Ic http , Ic server
.El
.Pp
Specifies the enabled ciphers.
The ciphers are specified in the format understood by the OpenSSL library, for
example:
.Bd -literal -offset indent
ssl_ciphers ALL:!aNULL:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
.Ed
.Pp
The full list can be viewed using the
.Ic openssl ciphers
command.
The previous versions of nginx used different ciphers by default.
.It Ic ssl_client_certificate Ar file
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server
.El
.Pp
Specifies a
.Ar file
with trusted CA certificates in the PEM format used to verify client
certificates and OCSP responses if
.Ic ssl_stapling
is enabled.
The list of certificates will be sent to clients.
If this is not desired, the
.Ic ssl_trusted_certificate
directive can be used.
.It Ic ssl_crl Ar file
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server
.El
.Pp
Specifies a
.Ar file
with revoked certificates (CRL) in the PEM format used to verify client
certificates.
.It Ic ssl_dhparam Ar file
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server
.El
.Pp
Specifies a
.Ar file
with DH parameters for EDH ciphers.
.It Ic ssl_prefer_server_ciphers Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server
.El
.Pp
Specifies that server ciphers should be preferred over client ciphers when using
the SSLv3 and TLS protocols.
.It Ic ssl_protocols Oo Cm SSLv2 Oc Oo Cm SSLv3 Oc Oo Cm TLSv1 Oc Oo Cm TLSv1.1 Oc Oo Cm TLSv1.2 Oc
.Bl -tag -width Ds -compact
.It default: SSLv3 TLSv1 TLSv1.1 TLSv1.2
.It context: Ic http , Ic server
.El
.Pp
Enables the specified protocols.
The
.Cm TLSv1.1
and
.Cm TLSv1.2
parameters work only when the OpenSSL library of version 1.0.1 or higher is
used.
The
.Cm TLSv1.1
and
.Cm TLSv1.2
parameters are supported starting from versions 1.1.13 and 1.0.12, so when the
OpenSSL version 1.0.1 or higher is used on older nginx versions, these protocols
work, but cannot be disabled.
.It Ic ssl_session_cache Cm off | Cm none | \
Oo Cm builtin Ns Oo : Ns Ar size Oc Oc Oo Cm shared: Ar name: Ar size Oc
.Bl -tag -width Ds -compact
.It default: Cm none
.It context: Ic http , Ic server
.El
.Pp
Sets the types and sizes of caches that store session parameters.
A cache can be of any of the following types:
.Bl -tag -width Ds
.It Cm off
the use of a session cache is strictly prohibited: nginx explicitly tells a
client that sessions may not be reused.
.It Cm none
the use of a session cache is gently disallowed: nginx tells a client that
sessions may be reused, but does not actually store session parameters in the
cache.
.It Cm builtin
a cache built in OpenSSL; used by one worker process only.
The cache size is specified in sessions.
If size is not given, it is equal to 20480 sessions.
Use of the built-in cache can cause memory fragmentation.
.It Cm shared
a cache shared between all worker processes.
The cache size is specified in bytes; one megabyte can store about 4000
sessions.
Each shared cache should have an arbitrary name.
A cache with the same name can be used in several virtual servers.
.El
.Pp
Both cache types can be used simultaneously, for example:
.Bd -literal -offset indent
ssl_session_cache builtin:1000 shared:SSL:10m;
.Ed
.Pp
but using only shared cache without the built-in cache should be more efficient.
.It Ic ssl_session_timeout Ar time
.Bl -tag -width Ds -compact
.It default: 5m
.It context: Ic http , Ic server
.El
.Pp
Specifies a time during which a client may reuse the session parameters stored
in a cache.
.It Ic ssl_stapling Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server
.El
.Pp
Enables or disables
stapling
of OCSP responses
by the server.
Example:
.Bd -literal -offset indent
ssl_stapling on;
resolver 192.0.2.1;
.Ed
.Pp
For the OCSP stapling to work, the certificate of the server certificate issuer
should be known.
If the
.Ic ssl_certificate
file does not contain intermediate certificates, the certificate of the server
certificate issuer should be present in the
.Ic ssl_trusted_certificate
file.
For a resolution of the OCSP responder hostname, the
.Ic resolver
directive should also be specified.
.It Ic ssl_stapling_file Ar file
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server
.El
.Pp
When set, the stapled OCSP response will be taken from the specified
.Ar file
instead of querying the OCSP responder specified in the server certificate.
The file should be in the DER format as produced by the
.Ic openssl ocsp
command.
.It Ic ssl_stapling_responder Ar url
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server
.El
.Pp
Overrides the URL of the OCSP responder specified in the
Authority
Information Access
certificate extension.
Only
.Qq http://
OCSP responders are supported:
.Bd -literal -offset indent
ssl_stapling_responder http://ocsp.example.com/;
.Ed
.It Ic ssl_stapling_verify Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server
.El
.Pp
Enables or disables verification of OCSP responses by the server.
For verification to work, the certificate of the server certificate issuer, the
root certificate, and all intermediate certificates should be configured as
trusted using the
.Ic ssl_trusted_certificate
directive.
.It Ic ssl_trusted_certificate Ar file
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server
.El
.Pp
Specifies a
.Ar file
with trusted CA certificates in the PEM format used to verify client
certificates and OCSP responses if
.Ic ssl_stapling
is enabled.
In contrast to the certificate set by
.Ic ssl_client_certificate ,
the list of these certificates will not be sent to clients.
.It Ic ssl_verify_client Cm on | Cm off | Cm optional | Cm optional_no_ca
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server
.El
.Pp
Enables verification of client certificates.
The verification result is stored in the
.Va $ssl_client_verify
variable.
The
.Cm optional
parameter (0.8.7+) requests the client certificate and verifies it if the
certificate is present.
The
.Cm optional_no_ca
parameter (1.3.8, 1.2.5) requests the client certificate but does not require it
to be signed by a trusted CA certificate.
This is intended for the use in cases when a service that is external to nginx
performs the actual certificate verification.
The contents of the certificate is accessible through the
.Va $ssl_client_cert
variable.
.It Ic ssl_verify_depth Ar number
.Bl -tag -width Ds -compact
.It default: 1
.It context: Ic http , Ic server
.El
.Pp
Sets the verification depth in the client certificates chain.
.El
.Ss Module ngx_http_status_module
.Em This module is only available in the commercial version of nginx.
.Bl -tag -width Ds
.It Ic status
.Bl -tag -width Ds -compact
.It default:
.It context: Ic location
.El
.Pp
The status information will be accessible from the surrounding location.
.It Ic status_format Cm json
.It Ic status_format Cm jsonp Oo Ar callback Oc
.Bl -tag -width Ds -compact
.It default: json
.It context: Ic http , Ic server , Ic location
.El
.Pp
By default, status information is output in the JSON format.
Alternatively, data may be output as JSONP.
The
.Ar callback
parameter specifies the name of a callback function.
The value can contain variables.
If parameter is omitted, or the computed value is an empty string, then
.Sx Module ngx_status_jsonp_callback
is used.
.El
.Ss Module ngx_http_stub_status_module
.Bl -tag -width Ds
.It Ic stub_status Cm on
.Bl -tag -width Ds -compact
.It default:
.It context: Ic location
.El
.Pp
The status information will be accessible from the surrounding location.
.El
.Ss Module ngx_http_sub_module
.Em This module is not enabled on OpenBSD.
.Bl -tag -width Ds
.It Ic sub_filter Ar string Ar replacement
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets a string to replace and a replacement string.
The string to replace is matched ignoring the case.
The replacement string can contain variables.
.It Ic sub_filter_last_modified Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Allows preserving the Last-Modified header field from the original response
during replacement to facilitate response caching.
By default, the header field is removed as contents of the response are modified
during processing.
.It Ic sub_filter_once Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm on
.It context: Ic http , Ic server , Ic location
.El
.Pp
Indicates whether to look for a string to replace once or several times.
.It Ic sub_filter_types Ar mime-type No ...
.Bl -tag -width Ds -compact
.It default: text/html
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables string replacement in responses with the specified MIME types in
addition to
.Ar text/html.
The special value
.Qq *
matches any MIME type (0.8.29).
.El
.Ss Module ngx_http_upstream_module
.Bl -tag -width Ds
.It Ic upstream Ar name Brq No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
Defines a group of servers.
Servers can listen on different ports.
In addition, servers listening on TCP and UNIX-domain sockets can be mixed.
Example:
.Bd -literal -offset indent
upstream backend {
server backend1.example.com weight=5;
server 127.0.0.1:8080 max_fails=3 fail_timeout=30s;
server unix:/tmp/backend3;
}
.Ed
.Pp
By default, requests are distributed between the servers using a weighted
round-robin balancing method.
In the above example, each 7 requests will be distributed as follows: 5 requests
go to
backend1.example.com
and one request to each of the second and third servers.
If an error occurs during communication with a server, the request will be
passed to the next server, and so on until all of the functioning servers will
be tried.
If a successful response could not be obtained from any of the servers, the
client will receive the result of the communication with the last server.
.It Ic server Ar address Oo Ar parameters Oc
.Bl -tag -width Ds -compact
.It default:
.It context: Ic upstream
.El
.Pp
Defines the
.Ar address
and other
.Ar parameters
of a server.
The address can be specified as a domain name or IP address, with an optional
port, or as a UNIX-domain socket path specified after the
.Cm unix:
prefix.
If a port is not specified, the port 80 is used.
A domain name that resolves to several IP addresses defines multiple servers at
once.
The following parameters can be defined:
.Bl -tag -width Ds
.It Cm weight Ns = Ns Ar number
sets the weight of the server, by default, 1.
.It Cm max_fails Ns = Ns Ar number
sets the number of unsuccessful attempts to communicate with the server that
should happen in the duration set by the
.Cm fail_timeout
parameter to consider the server unavailable for a duration also set by the
.Cm fail_timeout
parameter.
By default, the number of unsuccessful attempts is set to 1.
The zero value disables the accounting of attempts.
What is considered an unsuccessful attempt is defined by the
.Ic proxy_next_upstream ,
.Ic fastcgi_next_upstream ,
and
.Ic memcached_next_upstream
directives.
.It Cm fail_timeout Ns = Ns Ar time
sets
.Bl -bullet
.It
the time during which the specified number of unsuccessful attempts to
communicate with the server should happen to consider the server unavailable;
.It
and the period of time the server will be considered unavailable.
.El
.Pp
By default, the parameter is set to 10 seconds.
.It Cm slow_start Ns = Ns Ar time
sets the
.Ar time
during which the server will recover its weight from zero to a nominal value,
when unhealthy server becomes healthy, or when the server becomes available
after a period of time it was considered unavailable. Default value is zero,
i.e. slow start is disabled.
.Pp
.Em This option is only available in the commercial version of nginx.
.It Cm backup
marks the server as a backup server.
It will be passed requests when the primary servers are unavailable.
.It Cm down
marks the server as permanently unavailable; used along with the
.Ic ip_hash
directive.
.It Cm route Ns = Ns Ar string
sets the server route name.
.Pp
.Em This option is only available in the commercial version of nginx.
.El
.Pp
Example:
.Bd -literal -offset indent
upstream backend {
server backend1.example.com weight=5;
server 127.0.0.1:8080 max_fails=3 fail_timeout=30s;
server unix:/tmp/backend3;
server backup1.example.com:8080 backup;
}
.Ed
.Pp
If there is only a single server in a group,
.Cm max_fails ,
.Cm fail_timeout
and
.Cm slow_start
parameters are ignored, and such a server will never be considered unavailable.
.It Ic zone Ar name Ar size
.Bl -tag -width Ds -compact
.It default:
.It context: Ic upstream
.El
.Pp
.Em This directive is only available in the commercial version of nginx.
.Pp
Makes the group dynamically configurable.
Defines the
.Ar name
and
.Ar size
of a shared memory zone that keeps group's configuration and run-time state that
are shared between worker processes.
Such groups allow to add, remove, and modify servers at run time.
The configuration is accessible via a special location handled by
.Ic upstream_conf .
.It Ic ip_hash
.Bl -tag -width Ds -compact
.It default:
.It context: Ic upstream
.El
.Pp
Specifies that a group should use a load balancing method where requests are
distributed between servers based on client IP addresses.
The first three octets of the client IPv4 address, or the entire IPv6 address,
are used as a hashing key.
The method ensures that requests from the same client will always be passed to
the same server except when this server is unavailable.
In the latter case client requests will be passed to another server.
Most probably, it will always be the same server as well.
IPv6 addresses are supported starting from versions 1.3.2 and 1.2.2.
If one of the servers needs to be temporarily removed, it should be marked with
the
.Cm down
parameter in order to preserve the current hashing of client IP addresses.
Example:
.Bd -literal -offset indent
upstream backend {
ip_hash;
server backend1.example.com;
server backend2.example.com;
server backend3.example.com down;
server backend4.example.com;
}
.Ed
.Pp
Until versions 1.3.1 and 1.2.2, it was not possible to specify a weight for
servers using the
.Ic ip_hash
load balancing method.
.It Ic keepalive Ar connections
.Bl -tag -width Ds -compact
.It default:
.It context: Ic upstream
.El
.Pp
Activates the cache for connections to upstream servers.
The
.Ar connections
parameter sets the maximum number of idle keepalive connections to upstream
servers that are preserved in the cache of each worker process.
When this number is exceeded, the least recently used connections are closed.
It should be particularly noted that the
.Ic keepalive
directive does not limit the total number of connections to upstream servers
that an nginx worker process can open.
The
.Ar connections
parameter should be set to a number small enough to let upstream servers process
new incoming connections as well.
Example configuration of memcached upstream with keepalive connections:
.Bd -literal -offset indent
upstream memcached_backend {
server 127.0.0.1:11211;
server 10.0.0.2:11211;
keepalive 32;
}
server {
...
location /memcached/ {
set $memcached_key $uri;
memcached_pass memcached_backend;
}
}
.Ed
.Pp
For HTTP, the
.Ic proxy_http_version
directive should be set to
1.1
and the Connection header field should be cleared:
.Bd -literal -offset indent
upstream http_backend {
server 127.0.0.1:8080;
keepalive 16;
}
server {
...
location /http/ {
proxy_pass http://http_backend;
proxy_http_version 1.1;
proxy_set_header Connection "";
...
}
}
.Ed
.Pp
Alternatively, HTTP/1.0 persistent connections can be used by passing the
Connection: Keep-Alive header field to an upstream server, though this method is
not recommended.
For FastCGI servers, it is required to set
.Ic fastcgi_keep_conn
for keepalive connections to work:
.Bd -literal -offset indent
upstream fastcgi_backend {
server 127.0.0.1:9000;
keepalive 8;
}
server {
...
location /fastcgi/ {
fastcgi_pass fastcgi_backend;
fastcgi_keep_conn on;
...
}
}
.Ed
.Pp
When using load balancer methods other than the default round-robin method, it
is necessary to activate them before the
.Ic keepalive
directive.
SCGI and uwsgi protocols do not have a notion of keepalive connections.
.It Ic least_conn
.Bl -tag -width Ds -compact
.It default:
.It context: Ic upstream
.El
.Pp
Specifies that a group should use a load balancing method where a request is
passed to the server with the least number of active connections, taking into
account weights of servers.
If there are several such servers, they are tried using a weighted round-robin
balancing method.
.It Ic health_check Oo Cm interval Ns = Ns Ar time Oc Oo Cm fails Ns = Ns Ar number Oc Oo Cm passes Ns = Ns Ar number Oc Oo Cm uri Ns = Ns Ar uri Oc Oo Cm match Ns = Ns Ar name Oc
.Bl -tag -width Ds -compact
.It default:
.It context: Ic location
.El
.Pp
.Em This directive is only available in the commercial version of nginx.
.Pp
Enables periodic health checks of the servers in a
.Ic upstream
.Ar group
referenced in the surrounding location.
The following optional parameters are supported:
.Bl -bullet
.It
.Cm interval
sets the interval between two consecutive health checks, by default, 5 seconds;
.It
.Cm fails
sets the number of consecutive failed health checks of a particular server after
which this server will be considered unhealthy, by default, 1;
.It
.Cm passes
sets the number of consecutive passed health checks of a particular server after
which the server will be considered healthy, by default, 1;
.It
.Ar uri
defines the URI used in health check requests, by default,
.Qq / ;
.It
.Ic match
specifies the
.Ic match
block configuring the tests that a response should pass in order for a health
check to pass; by default, the response should have status code 2xx or 3xx.
.El
.Pp
For example,
.Bd -literal -offset indent
location / {
proxy_pass http://backend;
health_check;
}
.Ed
.Pp
will send
.Qq /
requests to each server in the
backend
group every five seconds.
If any communication error or timeout occurs, or a proxied server responds with
the status code other than 2xx or 3xx, the health check will fail, and the
server will be considered unhealthy.
Client requests are not passed to unhealthy servers.
Health checks can be configured to test the status code of a response, presence
of certain header fields and their values, and the body contents.
Tests are configured separately using the
.Ic match
directive and referenced in the
.Ic match
parameter.
For example:
.Bd -literal -offset indent
http {
server {
...
location / {
proxy_pass http://backend;
health_check match=welcome;
}
}
match welcome {
status 200;
header Content-Type = text/html;
body ~ "Welcome to nginx!";
}
}
.Ed
.Pp
This configuration tells that for a health check to pass, the response to a
health check request should succeed, have status 200, content type text/html,
and contain
.Qq Welcome to nginx!
in the body.
The server group must reside in the shared memory.
If several health checks are defined for the same group of servers, a single
failure of any check will make the corresponding server be considered unhealthy.
.It Ic match Ar name Brq No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http
.El
.Pp
.Em This directive is only available in the commercial version of nginx.
.Pp
Defines the named test set used to verify responses to health check requests.
The following items can be tested in a response:
.Bl -tag -width Ds
.It Cm status 200;
status is 200
.It Cm status ! 500;
status is not 500
.It Cm status 200 204;
status is 200 or 204
.It Cm status ! 301 302;
status is neither 301 nor 302
.It Cm status 200-399;
status is in the range from 200 to 399
.It Cm status ! 400-599;
status is not in the range from 400 to 599
.It Cm status 301-303 307;
status is either 301, 302, 303, or 307
.El
.Bl -tag -width Ds
.It Cm header Content-Type Ns = Ns Cm text/html;
header contains Content-Type with value text/html
.It Cm header Content-Type ! Ns = Ns Cm text/html;
header contains Content-Type with value other than text/html
.It Cm header Connection ~ close;
header contains Connection with value matching regular expression
close
.It Cm header Connection !~ close;
header contains Connection with value not matching regular expression
close
.It Cm header Host;
header contains Host
.It Cm header ! X-Accel-Redirect;
header lacks X-Accel-Redirect
.El
.Bl -tag -width Ds
.It Cm body ~ "Welcome to nginx!";
body matches regular expression
Welcome to nginx!
.It Cm body !~ "Welcome to nginx!";
body does not match regular expression
Welcome to nginx!
.El
.Pp
If several tests are specified, the response matches only if it matches all
tests.
Only the first 256k of the response body are examined.
Examples:
.Bd -literal -offset indent
# status is 200, content type is "text/html",
# and body contains "Welcome to nginx!"
match welcome {
status 200;
header Content-Type = text/html;
body ~ "Welcome to nginx!";
}
.Ed
.Bd -literal -offset indent
# status is not one of 301, 302, 303, or 307, and header does not have "Refresh:"
match not_redirect {
status ! 301-303 307;
header ! Refresh;
}
.Ed
.Bd -literal -offset indent
# status ok and not in maintenance mode
match server_ok {
status 200-399;
body !~ "maintenance mode";
}
.Ed
.It Ic sticky Cm cookie Ar name Oo Cm expires Ns = Ns Ar time Oc Oo Cm domain Ns = Ns Ar domain Oc Oo Cm path Ns = Ns Ar path Oc
.It Ic sticky Cm route Ar variable No ...
.Bl -tag -width Ds -compact
.It default:
.It context: Ic upstream
.El
.Pp
.Em This directive is only available in the commercial version of nginx.
.Pp
Enables session affinity, which causes requests from the same client to be
passed to the same server in a group of servers.
Two methods are available,
.Cm cookie
and
.Cm route .
When the
.Cm cookie
method is used, information about the designated server is passed in an HTTP
cookie:
.Bd -literal -offset indent
upstream backend {
server backend1.example.com;
server backend2.example.com;
sticky cookie srv_id expires=1h domain=.example.com path=/;
}
.Ed
.Pp
A request that comes from a client not yet bound to a particular server is
passed to the server selected by the configured balancing method.
Further requests from the same client are passed to the same server.
If the designated server cannot process a request, the new server is selected as
if the client has not been bound yet.
The first parameter sets the name of the cookie to be set or inspected.
Additional parameters may be as follows:
.Bl -tag -width Ds
.It Cm expires
Sets the time for which a browser should keep the cookie.
The special value
.Cm max
will cause the cookie to expire on
31 Dec 2037 23:55:55 GMT.
This is the maximum time understood by old browsers.
If the parameter is not specified, it will cause the cookie to expire at the end
of a browser session.
.It Cm domain
Defines the domain for which the cookie is set.
.It Cm path
Defines the path for which the cookie is set.
.El
.Pp
If any parameters are omitted, the corresponding cookie fields are not set.
When the
.Cm route
method is used, proxied server assigns client a route on receipt of the first
request.
All subsequent requests from this client will carry routing information in a
cookie or URI.
This information is compared with the
.Cm route
parameter of the
.Ic server
directive to identify the server to which the request should be proxied.
If the designated server cannot process a request, the new server is selected by
the configured balancing method as if there is no routing information in the
request.
The parameters of the
.Cm route
method specify variables that may contain routing information.
The first non-empty variable is used to find the matching server.
Example:
.Bd -literal -offset indent
map $cookie_jsessionid $route_cookie {
~.+\\.(?P<route>\\w+)$ $route;
}
map $request_uri $route_uri {
~jsessionid=.+\\.(?P<route>\\w+)$ $route;
}
upstream backend {
server backend1.example.com route=a;
server backend2.example.com route=b;
sticky route $route_cookie $route_uri;
}
.Ed
.Pp
Here, the route is taken from the
JSESSIONID
cookie if present in a request.
Otherwise, the route from the URI is used.
.It Ic sticky_cookie_insert Ar name Oo Cm expires Ns = Ns Ar time Oc Oo Cm domain Ns = Ns Ar domain Oc Oo Cm path Ns = Ns Ar path Oc
.Bl -tag -width Ds -compact
.It default:
.It context: Ic upstream
.El
.Pp
This directive is obsolete since version 1.5.7.
An equivalent
.Ic sticky
directive with a new syntax should be used instead:
.Ic sticky cookie Ar name Oo Cm expires Ns = Ns Ar time Oc Oo Cm domain Ns = Ns Ar domain Oc Oo Cm path Ns = Ns Ar path Oc ;
.It Ic upstream_conf
.Bl -tag -width Ds -compact
.It default:
.It context: Ic location
.El
.Pp
.Em This directive is only available in the commercial version of nginx.
.Pp
Turns on the HTTP interface of upstream configuration in the surrounding
location.
Access to this location should be
.Ic satisfy
limited .
Configuration commands can be used to:
.Bl -bullet
.It
view all primary or backup servers in a group;
.It
view an individual server;
.It
modify an individual server;
.It
add a new server (see the note below);
.It
remove an individual server.
.El
.Pp
As noted in the
.Ic server
directive, specifying a server as a domain name may result in several servers
being added to the group.
Since addresses in a group are not required to be unique, individual servers in
a group can be uniquely referenced to only by their ID.
IDs are assigned automatically and shown on viewing of the group configuration.
A configuration command consists of parameters passed as request arguments, for
example:
.Bd -literal -offset indent
http://127.0.0.1/upstream_conf?upstream=appservers
.Ed
.Pp
The following parameters are supported:
.Bl -tag -width Ds
.It Cm upstream Ns = Ns Ar name
Selects a group.
This parameter is mandatory.
.It Cm backup Ns =
If not set, selects primary servers in the group.
If set, selects backup servers in the group.
.It Cm id Ns = Ns Ar number
Selects an individual primary or backup server in the group.
.It Cm remove Ns =
Removes an individual primary or backup server from the group.
.It Cm add Ns =
Adds a new primary or backup server to the group.
.It Cm server Ns = Ns Ar address
Same as the
.Ar address
parameter of the
.Ic server
directive.
.It Cm weight Ns = Ns Ar number
Same as the
.Cm weight
parameter of the
.Ic server
directive.
.It Cm max_fails Ns = Ns Ar number
Same as the
.Cm max_fails
parameter of the
.Ic server
directive.
.It Cm fail_timeout Ns = Ns Ar time
Same as the
.Cm fail_timeout
parameter of the
.Ic server
directive.
.It Cm slow_start Ns = Ns Ar time
Same as the
.Cm slow_start
parameter of the
.Ic server
directive.
.It Cm down Ns =
Same as the
.Cm down
parameter of the
.Ic server
directive.
.It Cm up Ns =
The opposite of the
.Cm down
parameter of the
.Ic server
directive.
.It Cm route Ns = Ns Ar string
Same as the
.Cm route
parameter of the
.Ic server
directive.
.El
.Pp
The first three parameters select a target the command applies to.
Without other parameters, the command shows configuration of the selected
target.
For example, to view the primary servers in the group, send:
.Bd -literal -offset indent
http://127.0.0.1/upstream_conf?upstream=appservers
.Ed
.Pp
To view the backup servers in the group, send:
.Bd -literal -offset indent
http://127.0.0.1/upstream_conf?upstream=appservers&backup=
.Ed
.Pp
To view an individual primary server in the group, send:
.Bd -literal -offset indent
http://127.0.0.1/upstream_conf?upstream=appservers&id=42
.Ed
.Pp
To view an individual backup server in the group, send:
.Bd -literal -offset indent
http://127.0.0.1/upstream_conf?upstream=appservers&backup=&id=42
.Ed
.Pp
To add a new primary or backup server to the group, specify its address in the
.Ic server Ns =
parameter.
Without other parameters specified, a server will be added with other parameters
set to their default values (see the
.Ic server
directive).
For example, to add a new primary server to the group, send:
.Bd -literal -offset indent
http://127.0.0.1/upstream_conf?add=&upstream=appservers&server=127.0.0.1:8080
.Ed
.Pp
To add a new backup server to the group, send:
.Bd -literal -offset indent
http://127.0.0.1/upstream_conf?add=&upstream=appservers&backup=&server=127.0.0.1:8080
.Ed
.Pp
To add a new primary server to the group, set its parameters to non-default
values and mark it as
.Cm down ,
send:
.Bd -literal -offset indent
http://127.0.0.1/upstream_conf?add=&upstream=appservers&server=127.0.0.1:8080&weight=2&max_fails=3&fail_timeout=3s&down=
.Ed
.Pp
To remove an individual primary or backup server from the group, select it with
the
.Cm id Ns =
parameter.
For example, to remove an individual primary server from the group, send:
.Bd -literal -offset indent
http://127.0.0.1/upstream_conf?remove=&upstream=appservers&id=42
.Ed
.Pp
To remove an individual backup server from the group, send:
.Bd -literal -offset indent
http://127.0.0.1/upstream_conf?remove=&upstream=appservers&backup=&id=42
.Ed
.Pp
To modify an individual primary or backup server in the group, select it with
the
.Cm id Ns =
parameter.
For example, to modify an individual primary server in the group by marking it
as
.Cm down ,
send:
.Bd -literal -offset indent
http://127.0.0.1/upstream_conf?upstream=appservers&id=42&down=
.Ed
.Pp
To modify the address of an individual backup server in the group, send:
.Bd -literal -offset indent
http://127.0.0.1/upstream_conf?upstream=appservers&backup=&id=42&server=192.0.2.3:8123
.Ed
.Pp
To modify other parameters of an individual primary server in the group, send:
.Bd -literal -offset indent
http://127.0.0.1/upstream_conf?upstream=appservers&id=42&max_fails=3&weight=4
.Ed
.El
.Ss Module ngx_http_userid_module
.Bl -tag -width Ds
.It Ic userid Cm on | Cm v1 | Cm log | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables or disables setting cookies and logging the received cookies:
.Bl -tag -width Ds
.It Cm on
enables the setting of version 2 cookies and logging of the received cookies;
.It Cm v1
enables the setting of version 1 cookies and logging of the received cookies;
.It Cm log
disables the setting of cookies, but enables logging of the received cookies;
.It Cm off
disables the setting of cookies and logging of the received cookies.
.El
.It Ic userid_domain Ar name | Cm none
.Bl -tag -width Ds -compact
.It default: Cm none
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines a domain for which the cookie is set.
The
.Cm none
parameter disables setting of a domain for the cookie.
.It Ic userid_expires Ar time | Cm max | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets a time during which a browser should keep the cookie.
The parameter
.Cm max
will cause the cookie to expire on
31 Dec 2037 23:55:55 GMT.
This is the maximum time understood by old browsers.
The parameter
.Cm off
will cause the cookie to expire at the end of a browser session.
.It Ic userid_mark Ar letter | Ar digit | Ns = Ns | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
If the parameter is not
.Cm off ,
enables the cookie marking mechanism and sets the character used as a mark.
This mechanism is used to add or change
.Ic userid_p3p
and/or a cookie expiration time while preserving the client identifier.
A mark can be any letter of the English alphabet (case-sensitive), digit, or the
.Qq =
character.
If the mark is set, it is compared with the first padding symbol in the base64
representation of the client identifier passed in a cookie.
If they do not match, the cookie is resent with the specified mark, expiration
time, and P3P header.
.It Ic userid_name Ar name
.Bl -tag -width Ds -compact
.It default: uid
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets the cookie name.
.It Ic userid_p3p Ar string | Cm none
.Bl -tag -width Ds -compact
.It default: Cm none
.It context: Ic http , Ic server , Ic location
.El
.Pp
Sets a value for the P3P header field that will be sent along with the cookie.
If the directive is set to the special value
.Cm none ,
the P3P header will not be sent in a response.
.It Ic userid_path Ar path
.Bl -tag -width Ds -compact
.It default: /
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines a path for which the cookie is set.
.It Ic userid_service Ar number
.Bl -tag -width Ds -compact
.It default: IP address of the server
.It context: Ic http , Ic server , Ic location
.El
.Pp
If identifiers are issued by multiple servers (services), each service should be
assigned its own
.Ar number
to ensure that client identifiers are unique.
For version 1 cookies, the default value is zero.
For version 2 cookies, the default value is the number composed from the last
four octets of the server's IP address.
.El
.Ss Module ngx_http_xslt_module
.Em This module is not enabled on OpenBSD.
.Bl -tag -width Ds
.It Ic xml_entities Ar path
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Specifies the DTD file that declares character entities.
This file is compiled at the configuration stage.
For technical reasons, the module is unable to use the external subset declared
in the processed XML, so it is ignored and a specially defined file is used
instead.
This file should not describe the XML structure.
It is enough to declare just the required character entities, for example:
.Bd -literal -offset indent
<!ENTITY nbsp " ">
.Ed
.It Ic xslt_last_modified Cm on | Cm off
.Bl -tag -width Ds -compact
.It default: Cm off
.It context: Ic http , Ic server , Ic location
.El
.Pp
Allows preserving the Last-Modified header field from the original response
during XSLT transformations to facilitate response caching.
By default, the header field is removed as contents of the response are modified
during transformations and may contain dynamically generated elements or parts
that are changed independently of the original response.
.It Ic xslt_param Ar parameter Ar value
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines the parameters for XSLT stylesheets.
The
.Ar value
is treated as an XPath expression.
The
.Ar value
can contain variables.
To pass a string value to a stylesheet, the
.Ic xslt_string_param
directive can be used.
There could be several
.Ic xslt_param
directives.
These directives are inherited from the previous level if and only if there are
no
.Ic xslt_param
and
.Ic xslt_string_param
directives defined on the current level.
.It Ic xslt_string_param Ar parameter Ar value
.Bl -tag -width Ds -compact
.It default:
.It context: Ic http , Ic server , Ic location
.El
.Pp
Defines the string parameters for XSLT stylesheets.
XPath expressions in the
.Ar value
are not interpreted.
The
.Ar value
can contain variables.
There could be several
.Ic xslt_string_param
directives.
These directives are inherited from the previous level if and only if there are
no
.Ic xslt_param
and
.Ic xslt_string_param
directives defined on the current level.
.It Ic xslt_stylesheet Ar stylesheet Oo Ar parameter Ns = Ns Ar value No ... Oc
.Bl -tag -width Ds -compact
.It default:
.It context: Ic location
.El
.Pp
Defines the XSLT stylesheet and its optional parameters.
A stylesheet is compiled at the configuration stage.
Parameters can either be specified separately, or grouped in a single line using
the
.Qo : Qc
delimiter.
If a parameter includes the
.Qo : Qc
character, it should be escaped as
.Qq %3A .
Also,
.Lb libxslt
requires to enclose parameters that contain non-alphanumeric characters into
single or double quotes, for example:
.Bd -literal -offset indent
param1='http%3A//www.example.com':param2=value2
.Ed
.Pp
The parameters description can contain variables, for example, the whole line of
parameters can be taken from a single variable:
.Bd -literal -offset indent
location / {
xslt_stylesheet /site/xslt/one.xslt
$arg_xslt_params
param1='$value1':param2=value2
param3=value3;
}
.Ed
.Pp
It is possible to specify several stylesheets.
They will be applied sequentially in the specified order.
.It Ic xslt_types Ar mime-type No ...
.Bl -tag -width Ds -compact
.It default: text/xml
.It context: Ic http , Ic server , Ic location
.El
.Pp
Enables transformations in responses with the specified MIME types in addition
to text/xml.
The special value
.Qq *
matches any MIME type (0.8.29).
If the transformation result is an HTML response, its MIME type is changed to
text/html.
.El
.Sh FILES
.Pa /etc/nginx/nginx.conf
.Sh EXAMPLES
The following is a valid configuration file, but such creative use
of whitespace is not recommended:
.Bd -offset indent -literal
worker_processes #whitespace is required here
auto
#a comment is allowed here
;events{}user #whitespace is again required here
www
#and here, too
www;# but not here
.Ed
.Sh SEE ALSO
.Xr nginx 8
|