Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nginx
GitHub Repository: nginx/nginx.org
Path: blob/main/xml/en/docs/http/ngx_http_fastcgi_module.xml
1 views
1
<?xml version="1.0"?>
2
3
<!--
4
Copyright (C) Igor Sysoev
5
Copyright (C) Nginx, Inc.
6
-->
7
8
<!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">
9
10
<module name="Module ngx_http_fastcgi_module"
11
link="/en/docs/http/ngx_http_fastcgi_module.html"
12
lang="en"
13
rev="56">
14
15
<section id="summary">
16
17
<para>
18
The <literal>ngx_http_fastcgi_module</literal> module allows passing
19
requests to a FastCGI server.
20
</para>
21
22
</section>
23
24
25
<section id="example" name="Example Configuration">
26
27
<para>
28
<example>
29
location / {
30
fastcgi_pass localhost:9000;
31
fastcgi_index index.php;
32
33
fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
34
fastcgi_param QUERY_STRING $query_string;
35
fastcgi_param REQUEST_METHOD $request_method;
36
fastcgi_param CONTENT_TYPE $content_type;
37
fastcgi_param CONTENT_LENGTH $content_length;
38
}
39
</example>
40
</para>
41
42
</section>
43
44
45
<section id="directives" name="Directives">
46
47
<directive name="fastcgi_allow_upstream">
48
<syntax><value>string</value> ...</syntax>
49
<default/>
50
<context>http</context>
51
<context>server</context>
52
<context>location</context>
53
<appeared-in>1.29.3</appeared-in>
54
55
<para>
56
Defines conditions under which access to a FastCGI server
57
is allowed or <link id="denied">denied</link>.
58
If all string parameters are not empty
59
and not equal to “0” then the access is allowed.
60
The conditions are evaluated each time
61
before a connection to a FastCGI server is established.
62
Parameter values can contain variables:
63
<example>
64
geo $upstream_last_addr $allow {
65
volatile;
66
10.10.0.0/24 1;
67
}
68
69
server {
70
listen 127.0.0.1:8080;
71
72
location / {
73
fastcgi_pass localhost:9000;
74
fastcgi_allow_upstream $allow;
75
...
76
}
77
}
78
</example>
79
</para>
80
81
<para>
82
<note>
83
This directive is available as part of our
84
<commercial_version>commercial subscription</commercial_version>.
85
</note>
86
</para>
87
88
</directive>
89
90
91
<directive name="fastcgi_bind">
92
<syntax>
93
<value>address</value>
94
[<literal>transparent</literal>] |
95
<literal>off</literal></syntax>
96
<default/>
97
<context>http</context>
98
<context>server</context>
99
<context>location</context>
100
<appeared-in>0.8.22</appeared-in>
101
102
<para>
103
Makes outgoing connections to a FastCGI server originate
104
from the specified local IP address with an optional port (1.11.2).
105
Parameter value can contain variables (1.3.12).
106
The special value <literal>off</literal> (1.3.12) cancels the effect
107
of the <literal>fastcgi_bind</literal> directive
108
inherited from the previous configuration level, which allows the
109
system to auto-assign the local IP address and port.
110
</para>
111
112
<para id="fastcgi_bind_transparent">
113
The <literal>transparent</literal> parameter (1.11.0) allows
114
outgoing connections to a FastCGI server originate
115
from a non-local IP address,
116
for example, from a real IP address of a client:
117
<example>
118
fastcgi_bind $remote_addr transparent;
119
</example>
120
In order for this parameter to work,
121
it is usually necessary to run nginx worker processes with the
122
<link doc="../ngx_core_module.xml" id="user">superuser</link> privileges.
123
On Linux it is not required (1.13.8) as if
124
the <literal>transparent</literal> parameter is specified, worker processes
125
inherit the <literal>CAP_NET_RAW</literal> capability from the master process.
126
It is also necessary to configure kernel routing table
127
to intercept network traffic from the FastCGI server.
128
</para>
129
130
</directive>
131
132
133
<directive name="fastcgi_bind_dynamic">
134
<syntax><literal>on</literal> | <literal>off</literal></syntax>
135
<default>off</default>
136
<context>http</context>
137
<context>server</context>
138
<context>location</context>
139
<appeared-in>1.29.3</appeared-in>
140
141
<para>
142
When enabled, makes the <link id="fastcgi_bind">bind</link> operation
143
at each connection attempt.
144
</para>
145
146
<para>
147
<note>
148
This directive is available as part of our
149
<commercial_version>commercial subscription</commercial_version>.
150
</note>
151
</para>
152
153
</directive>
154
155
156
<directive name="fastcgi_buffer_size">
157
<syntax><value>size</value></syntax>
158
<default>4k|8k</default>
159
<context>http</context>
160
<context>server</context>
161
<context>location</context>
162
163
<para>
164
Sets the <value>size</value> of the buffer used for reading the first part
165
of the response received from the FastCGI server.
166
This part usually contains a small response header;
167
if it exceeds the buffer size, the response is considered
168
<link id="invalid_header">invalid</link>.
169
By default, the buffer size is equal to one memory page.
170
This is either 4K or 8K, depending on a platform.
171
It can be made smaller, however.
172
</para>
173
174
</directive>
175
176
177
<directive name="fastcgi_buffering">
178
<syntax><literal>on</literal> | <literal>off</literal></syntax>
179
<default>on</default>
180
<context>http</context>
181
<context>server</context>
182
<context>location</context>
183
<appeared-in>1.5.6</appeared-in>
184
185
<para>
186
Enables or disables buffering of responses from the FastCGI server.
187
</para>
188
189
<para>
190
When buffering is enabled, nginx receives a response from the FastCGI server
191
as soon as possible, saving it into the buffers set by the
192
<link id="fastcgi_buffer_size"/> and <link id="fastcgi_buffers"/> directives.
193
If the whole response does not fit into memory, a part of it can be saved
194
to a <link id="fastcgi_temp_path">temporary file</link> on the disk.
195
Writing to temporary files is controlled by the
196
<link id="fastcgi_max_temp_file_size"/> and
197
<link id="fastcgi_temp_file_write_size"/> directives.
198
</para>
199
200
<para>
201
When buffering is disabled, the response is passed to a client synchronously,
202
immediately as it is received.
203
nginx will not try to read the whole response from the FastCGI server.
204
The maximum size of the data that nginx can receive from the server
205
at a time is set by the <link id="fastcgi_buffer_size"/> directive.
206
</para>
207
208
<para>
209
Buffering can also be enabled or disabled by passing
210
<literal>yes</literal>” or “<literal>no</literal>” in the
211
<header>X-Accel-Buffering</header> response header field.
212
This capability can be disabled using the
213
<link id="fastcgi_ignore_headers"/> directive.
214
</para>
215
216
</directive>
217
218
219
<directive name="fastcgi_buffers">
220
<syntax><value>number</value> <value>size</value></syntax>
221
<default>8 4k|8k</default>
222
<context>http</context>
223
<context>server</context>
224
<context>location</context>
225
226
<para>
227
Sets the <value>number</value> and <value>size</value> of the
228
buffers used for reading a response from the FastCGI server,
229
for a single connection.
230
By default, the buffer size is equal to one memory page.
231
This is either 4K or 8K, depending on a platform.
232
</para>
233
234
</directive>
235
236
237
<directive name="fastcgi_busy_buffers_size">
238
<syntax><value>size</value></syntax>
239
<default>8k|16k</default>
240
<context>http</context>
241
<context>server</context>
242
<context>location</context>
243
244
<para>
245
When <link id="fastcgi_buffering">buffering</link> of responses from the FastCGI
246
server is enabled, limits the total <value>size</value> of buffers that
247
can be busy sending a response to the client while the response is not
248
yet fully read.
249
In the meantime, the rest of the buffers can be used for reading the response
250
and, if needed, buffering part of the response to a temporary file.
251
By default, <value>size</value> is limited by the size of two buffers set by the
252
<link id="fastcgi_buffer_size"/> and <link id="fastcgi_buffers"/> directives.
253
</para>
254
255
</directive>
256
257
258
<directive name="fastcgi_cache">
259
<syntax><value>zone</value> | <literal>off</literal></syntax>
260
<default>off</default>
261
<context>http</context>
262
<context>server</context>
263
<context>location</context>
264
265
<para>
266
Defines a shared memory zone used for caching.
267
The same zone can be used in several places.
268
Parameter value can contain variables (1.7.9).
269
The <literal>off</literal> parameter disables caching inherited
270
from the previous configuration level.
271
</para>
272
273
</directive>
274
275
276
<directive name="fastcgi_cache_background_update">
277
<syntax><literal>on</literal> | <literal>off</literal></syntax>
278
<default>off</default>
279
<context>http</context>
280
<context>server</context>
281
<context>location</context>
282
<appeared-in>1.11.10</appeared-in>
283
284
<para>
285
Allows starting a background subrequest
286
to update an expired cache item,
287
while a stale cached response is returned to the client.
288
Note that it is necessary to
289
<link id="fastcgi_cache_use_stale_updating">allow</link>
290
the usage of a stale cached response when it is being updated.
291
</para>
292
293
</directive>
294
295
296
<directive name="fastcgi_cache_bypass">
297
<syntax><value>string</value> ...</syntax>
298
<default/>
299
<context>http</context>
300
<context>server</context>
301
<context>location</context>
302
303
<para>
304
Defines conditions under which the response will not be taken from a cache.
305
If at least one value of the string parameters is not empty and is not
306
equal to “0” then the response will not be taken from the cache:
307
<example>
308
fastcgi_cache_bypass $cookie_nocache $arg_nocache$arg_comment;
309
fastcgi_cache_bypass $http_pragma $http_authorization;
310
</example>
311
Can be used along with the <link id="fastcgi_no_cache"/> directive.
312
</para>
313
314
</directive>
315
316
317
<directive name="fastcgi_cache_key">
318
<syntax><value>string</value></syntax>
319
<default/>
320
<context>http</context>
321
<context>server</context>
322
<context>location</context>
323
324
<para>
325
Defines a key for caching, for example
326
<example>
327
fastcgi_cache_key localhost:9000$request_uri;
328
</example>
329
</para>
330
331
</directive>
332
333
334
<directive name="fastcgi_cache_lock">
335
<syntax><literal>on</literal> | <literal>off</literal></syntax>
336
<default>off</default>
337
<context>http</context>
338
<context>server</context>
339
<context>location</context>
340
<appeared-in>1.1.12</appeared-in>
341
342
<para>
343
When enabled, only one request at a time will be allowed to populate
344
a new cache element identified according to the <link id="fastcgi_cache_key"/>
345
directive by passing a request to a FastCGI server.
346
Other requests of the same cache element will either wait
347
for a response to appear in the cache or the cache lock for
348
this element to be released, up to the time set by the
349
<link id="fastcgi_cache_lock_timeout"/> directive.
350
</para>
351
352
</directive>
353
354
355
<directive name="fastcgi_cache_lock_age">
356
<syntax><value>time</value></syntax>
357
<default>5s</default>
358
<context>http</context>
359
<context>server</context>
360
<context>location</context>
361
<appeared-in>1.7.8</appeared-in>
362
363
<para>
364
If the last request passed to the FastCGI server
365
for populating a new cache element
366
has not completed for the specified <value>time</value>,
367
one more request may be passed to the FastCGI server.
368
</para>
369
370
</directive>
371
372
373
<directive name="fastcgi_cache_lock_timeout">
374
<syntax><value>time</value></syntax>
375
<default>5s</default>
376
<context>http</context>
377
<context>server</context>
378
<context>location</context>
379
<appeared-in>1.1.12</appeared-in>
380
381
<para>
382
Sets a timeout for <link id="fastcgi_cache_lock"/>.
383
When the <value>time</value> expires,
384
the request will be passed to the FastCGI server,
385
however, the response will not be cached.
386
<note>
387
Before 1.7.8, the response could be cached.
388
</note>
389
</para>
390
391
</directive>
392
393
394
<directive name="fastcgi_cache_max_range_offset">
395
<syntax><value>number</value></syntax>
396
<default/>
397
<context>http</context>
398
<context>server</context>
399
<context>location</context>
400
<appeared-in>1.11.6</appeared-in>
401
402
<para>
403
Sets an offset in bytes for byte-range requests.
404
If the range is beyond the offset,
405
the range request will be passed to the FastCGI server
406
and the response will not be cached.
407
</para>
408
409
</directive>
410
411
412
<directive name="fastcgi_cache_methods">
413
<syntax>
414
<literal>GET</literal> |
415
<literal>HEAD</literal> |
416
<literal>POST</literal>
417
...</syntax>
418
<default>GET HEAD</default>
419
<context>http</context>
420
<context>server</context>
421
<context>location</context>
422
<appeared-in>0.7.59</appeared-in>
423
424
<para>
425
If the client request method is listed in this directive then
426
the response will be cached.
427
<literal>GET</literal>” and “<literal>HEAD</literal>” methods are always
428
added to the list, though it is recommended to specify them explicitly.
429
See also the <link id="fastcgi_no_cache"/> directive.
430
</para>
431
432
</directive>
433
434
435
<directive name="fastcgi_cache_min_uses">
436
<syntax><value>number</value></syntax>
437
<default>1</default>
438
<context>http</context>
439
<context>server</context>
440
<context>location</context>
441
442
<para>
443
Sets the <value>number</value> of requests after which the response
444
will be cached.
445
</para>
446
447
</directive>
448
449
450
<directive name="fastcgi_cache_path">
451
<syntax>
452
<value>path</value>
453
[<literal>levels</literal>=<value>levels</value>]
454
[<literal>use_temp_path</literal>=<literal>on</literal>|<literal>off</literal>]
455
<literal>keys_zone</literal>=<value>name</value>:<value>size</value>
456
[<literal>inactive</literal>=<value>time</value>]
457
[<literal>max_size</literal>=<value>size</value>]
458
[<literal>min_free</literal>=<value>size</value>]
459
[<literal>manager_files</literal>=<value>number</value>]
460
[<literal>manager_sleep</literal>=<value>time</value>]
461
[<literal>manager_threshold</literal>=<value>time</value>]
462
[<literal>loader_files</literal>=<value>number</value>]
463
[<literal>loader_sleep</literal>=<value>time</value>]
464
[<literal>loader_threshold</literal>=<value>time</value>]
465
[<literal>purger</literal>=<literal>on</literal>|<literal>off</literal>]
466
[<literal>purger_files</literal>=<value>number</value>]
467
[<literal>purger_sleep</literal>=<value>time</value>]
468
[<literal>purger_threshold</literal>=<value>time</value>]</syntax>
469
<default/>
470
<context>http</context>
471
472
<para>
473
Sets the path and other parameters of a cache.
474
Cache data are stored in files.
475
Both the key and file name in a cache are a result of
476
applying the MD5 function to the proxied URL.
477
478
The <literal>levels</literal> parameter defines hierarchy levels of a cache:
479
from 1 to 3, each level accepts values 1 or 2.
480
For example, in the following configuration
481
<example>
482
fastcgi_cache_path /data/nginx/cache levels=1:2 keys_zone=one:10m;
483
</example>
484
file names in a cache will look like this:
485
<example>
486
/data/nginx/cache/<emphasis>c</emphasis>/<emphasis>29</emphasis>/b7f54b2df7773722d382f4809d650<emphasis>29c</emphasis>
487
</example>
488
</para>
489
490
<para>
491
A cached response is first written to a temporary file,
492
and then the file is renamed.
493
Starting from version 0.8.9, temporary files and the cache can be put on
494
different file systems.
495
However, be aware that in this case a file is copied
496
across two file systems instead of the cheap renaming operation.
497
It is thus recommended that for any given location both cache and a directory
498
holding temporary files
499
are put on the same file system.
500
A directory for temporary files is set based on
501
the <literal>use_temp_path</literal> parameter (1.7.10).
502
If this parameter is omitted or set to the value <literal>on</literal>,
503
the directory set by the <link id="fastcgi_temp_path"/> directive
504
for the given location will be used.
505
If the value is set to <literal>off</literal>,
506
temporary files will be put directly in the cache directory.
507
</para>
508
509
<para>
510
In addition, all active keys and information about data are stored
511
in a shared memory zone, whose <value>name</value> and <value>size</value>
512
are configured by the <literal>keys_zone</literal> parameter.
513
One megabyte zone can store about 8 thousand keys.
514
<note>
515
As part of
516
<commercial_version>commercial subscription</commercial_version>,
517
the shared memory zone also stores extended
518
cache <link doc="ngx_http_api_module.xml" id="http_caches_">information</link>,
519
thus, it is required to specify a larger zone size for the same number of keys.
520
For example,
521
one megabyte zone can store about 4 thousand keys.
522
</note>
523
</para>
524
525
<para>
526
Cached data that are not accessed during the time specified by the
527
<literal>inactive</literal> parameter get removed from the cache
528
regardless of their freshness.
529
By default, <literal>inactive</literal> is set to 10 minutes.
530
</para>
531
532
<para id="fastcgi_cache_path_max_size">
533
The special “cache manager” process monitors the maximum cache size set
534
by the <literal>max_size</literal> parameter,
535
and the minimum amount of free space set
536
by the <literal>min_free</literal> (1.19.1) parameter
537
on the file system with cache.
538
When the size is exceeded or there is not enough free space,
539
it removes the least recently used data.
540
The data is removed in iterations configured by
541
<literal>manager_files</literal>,
542
<literal>manager_threshold</literal>, and
543
<literal>manager_sleep</literal> parameters (1.11.5).
544
During one iteration no more than <literal>manager_files</literal> items
545
are deleted (by default, 100).
546
The duration of one iteration is limited by the
547
<literal>manager_threshold</literal> parameter (by default, 200 milliseconds).
548
Between iterations, a pause configured by the <literal>manager_sleep</literal>
549
parameter (by default, 50 milliseconds) is made.
550
</para>
551
552
<para>
553
A minute after the start the special “cache loader” process is activated.
554
It loads information about previously cached data stored on file system
555
into a cache zone.
556
The loading is also done in iterations.
557
During one iteration no more than <literal>loader_files</literal> items
558
are loaded (by default, 100).
559
Besides, the duration of one iteration is limited by the
560
<literal>loader_threshold</literal> parameter (by default, 200 milliseconds).
561
Between iterations, a pause configured by the <literal>loader_sleep</literal>
562
parameter (by default, 50 milliseconds) is made.
563
</para>
564
565
<para>
566
Additionally,
567
the following parameters are available as part of our
568
<commercial_version>commercial subscription</commercial_version>:
569
</para>
570
571
<para>
572
<list type="tag">
573
574
<tag-name id="purger">
575
<literal>purger</literal>=<literal>on</literal>|<literal>off</literal>
576
</tag-name>
577
<tag-desc>
578
Instructs whether cache entries that match a
579
<link id="fastcgi_cache_purge">wildcard key</link>
580
will be removed from the disk by the cache purger (1.7.12).
581
Setting the parameter to <literal>on</literal>
582
(default is <literal>off</literal>)
583
will activate the “cache purger” process that
584
permanently iterates through all cache entries
585
and deletes the entries that match the wildcard key.
586
</tag-desc>
587
588
<tag-name id="purger_files">
589
<literal>purger_files</literal>=<value>number</value>
590
</tag-name>
591
<tag-desc>
592
Sets the number of items that will be scanned during one iteration (1.7.12).
593
By default, <literal>purger_files</literal> is set to 10.
594
</tag-desc>
595
596
<tag-name id="purger_threshold">
597
<literal>purger_threshold</literal>=<value>number</value>
598
</tag-name>
599
<tag-desc>
600
Sets the duration of one iteration (1.7.12).
601
By default, <literal>purger_threshold</literal> is set to 50 milliseconds.
602
</tag-desc>
603
604
<tag-name id="purger_sleep">
605
<literal>purger_sleep</literal>=<value>number</value>
606
</tag-name>
607
<tag-desc>
608
Sets a pause between iterations (1.7.12).
609
By default, <literal>purger_sleep</literal> is set to 50 milliseconds.
610
</tag-desc>
611
612
</list>
613
</para>
614
615
<para>
616
<note>
617
In versions 1.7.3, 1.7.7, and 1.11.10 cache header format has been changed.
618
Previously cached responses will be considered invalid
619
after upgrading to a newer nginx version.
620
</note>
621
</para>
622
623
</directive>
624
625
626
<directive name="fastcgi_cache_purge">
627
<syntax>string ...</syntax>
628
<default/>
629
<context>http</context>
630
<context>server</context>
631
<context>location</context>
632
<appeared-in>1.5.7</appeared-in>
633
634
<para>
635
Defines conditions under which the request will be considered a cache
636
purge request.
637
If at least one value of the string parameters is not empty and is not equal
638
to “0” then the cache entry with a corresponding
639
<link id="fastcgi_cache_key">cache key</link> is removed.
640
The result of successful operation is indicated by returning
641
the <http-status code="204" text="No Content"/> response.
642
</para>
643
644
<para>
645
If the <link id="fastcgi_cache_key">cache key</link> of a purge request ends
646
with an asterisk (“<literal>*</literal>”), all cache entries matching the
647
wildcard key will be removed from the cache.
648
However, these entries will remain on the disk until they are deleted
649
for either <link id="fastcgi_cache_path">inactivity</link>,
650
or processed by the <link id="purger">cache purger</link> (1.7.12),
651
or a client attempts to access them.
652
</para>
653
654
<para>
655
Example configuration:
656
<example>
657
fastcgi_cache_path /data/nginx/cache keys_zone=cache_zone:10m;
658
659
map $request_method $purge_method {
660
PURGE 1;
661
default 0;
662
}
663
664
server {
665
...
666
location / {
667
fastcgi_pass backend;
668
fastcgi_cache cache_zone;
669
fastcgi_cache_key $uri;
670
fastcgi_cache_purge $purge_method;
671
}
672
}
673
</example>
674
<note>
675
This functionality is available as part of our
676
<commercial_version>commercial subscription</commercial_version>.
677
</note>
678
</para>
679
680
</directive>
681
682
683
<directive name="fastcgi_cache_revalidate">
684
<syntax><literal>on</literal> | <literal>off</literal></syntax>
685
<default>off</default>
686
<context>http</context>
687
<context>server</context>
688
<context>location</context>
689
<appeared-in>1.5.7</appeared-in>
690
691
<para>
692
Enables revalidation of expired cache items using conditional requests with
693
the <header>If-Modified-Since</header> and <header>If-None-Match</header>
694
header fields.
695
</para>
696
697
</directive>
698
699
700
<directive name="fastcgi_cache_use_stale">
701
<syntax>
702
<literal>error</literal> |
703
<literal>timeout</literal> |
704
<literal>invalid_header</literal> |
705
<literal>updating</literal> |
706
<literal>http_500</literal> |
707
<literal>http_503</literal> |
708
<literal>http_403</literal> |
709
<literal>http_404</literal> |
710
<literal>http_429</literal> |
711
<literal>off</literal>
712
...</syntax>
713
<default>off</default>
714
<context>http</context>
715
<context>server</context>
716
<context>location</context>
717
718
<para>
719
Determines in which cases a stale cached response can be used
720
when an error occurs during communication with the FastCGI server.
721
The directive’s parameters match the parameters of the
722
<link id="fastcgi_next_upstream"/> directive.
723
</para>
724
725
<para>
726
The <literal>error</literal> parameter also permits
727
using a stale cached response if a FastCGI server to process a request
728
cannot be selected.
729
</para>
730
731
<para id="fastcgi_cache_use_stale_updating">
732
Additionally, the <literal>updating</literal> parameter permits
733
using a stale cached response if it is currently being updated.
734
This allows minimizing the number of accesses to FastCGI servers
735
when updating cached data.
736
</para>
737
738
<para>
739
Using a stale cached response
740
can also be enabled directly in the response header
741
for a specified number of seconds after the response became stale (1.11.10).
742
This has lower priority than using the directive parameters.
743
<list type="bullet" compact="no">
744
745
<listitem>
746
The
747
<link url="https://datatracker.ietf.org/doc/html/rfc5861#section-3">stale-while-revalidate</link>
748
extension of the <header>Cache-Control</header> header field permits
749
using a stale cached response if it is currently being updated.
750
</listitem>
751
752
<listitem>
753
The
754
<link url="https://datatracker.ietf.org/doc/html/rfc5861#section-4">stale-if-error</link>
755
extension of the <header>Cache-Control</header> header field permits
756
using a stale cached response in case of an error.
757
</listitem>
758
759
</list>
760
</para>
761
762
<para>
763
To minimize the number of accesses to FastCGI servers when
764
populating a new cache element, the <link id="fastcgi_cache_lock"/>
765
directive can be used.
766
</para>
767
768
</directive>
769
770
771
<directive name="fastcgi_cache_valid">
772
<syntax>[<value>code</value> ...] <value>time</value></syntax>
773
<default/>
774
<context>http</context>
775
<context>server</context>
776
<context>location</context>
777
778
<para>
779
Sets caching time for different response codes.
780
For example, the following directives
781
<example>
782
fastcgi_cache_valid 200 302 10m;
783
fastcgi_cache_valid 404 1m;
784
</example>
785
set 10 minutes of caching for responses with codes 200 and 302
786
and 1 minute for responses with code 404.
787
</para>
788
789
<para>
790
If only caching <value>time</value> is specified
791
<example>
792
fastcgi_cache_valid 5m;
793
</example>
794
then only 200, 301, and 302 responses are cached.
795
</para>
796
797
<para>
798
In addition, the <literal>any</literal> parameter can be specified
799
to cache any responses:
800
<example>
801
fastcgi_cache_valid 200 302 10m;
802
fastcgi_cache_valid 301 1h;
803
fastcgi_cache_valid any 1m;
804
</example>
805
</para>
806
807
<para>
808
Parameters of caching can also be set directly
809
in the response header.
810
This has higher priority than setting of caching time using the directive.
811
<list type="bullet" compact="no">
812
813
<listitem>
814
The <header>X-Accel-Expires</header> header field sets caching time of a
815
response in seconds.
816
The zero value disables caching for a response.
817
If the value starts with the <literal>@</literal> prefix, it sets an absolute
818
time in seconds since Epoch, up to which the response may be cached.
819
</listitem>
820
821
<listitem>
822
If the header does not include the <header>X-Accel-Expires</header> field,
823
parameters of caching may be set in the header fields
824
<header>Expires</header> or <header>Cache-Control</header>.
825
</listitem>
826
827
<listitem>
828
If the header includes the <header>Set-Cookie</header> field, such a
829
response will not be cached.
830
</listitem>
831
832
<listitem>
833
If the header includes the <header>Vary</header> field
834
with the special value “<literal>*</literal>”, such a
835
response will not be cached (1.7.7).
836
If the header includes the <header>Vary</header> field
837
with another value, such a response will be cached
838
taking into account the corresponding request header fields (1.7.7).
839
</listitem>
840
841
</list>
842
Processing of one or more of these response header fields can be disabled
843
using the <link id="fastcgi_ignore_headers"/> directive.
844
</para>
845
846
</directive>
847
848
849
<directive name="fastcgi_catch_stderr">
850
<syntax><value>string</value></syntax>
851
<default/>
852
<context>http</context>
853
<context>server</context>
854
<context>location</context>
855
856
<para>
857
Sets a string to search for in the error stream of a response
858
received from a FastCGI server.
859
If the <value>string</value> is found then it is considered that the FastCGI
860
server has returned an <link id="fastcgi_next_upstream">invalid response</link>.
861
This allows handling application errors in nginx, for example:
862
<example>
863
location /php/ {
864
fastcgi_pass backend:9000;
865
...
866
fastcgi_catch_stderr "PHP Fatal error";
867
fastcgi_next_upstream error timeout invalid_header;
868
}
869
</example>
870
</para>
871
872
</directive>
873
874
875
<directive name="fastcgi_connect_timeout">
876
<syntax><value>time</value></syntax>
877
<default>60s</default>
878
<context>http</context>
879
<context>server</context>
880
<context>location</context>
881
882
<para>
883
Defines a timeout for establishing a connection with a FastCGI server.
884
It should be noted that this timeout cannot usually exceed 75 seconds.
885
</para>
886
887
</directive>
888
889
890
<directive name="fastcgi_force_ranges">
891
<syntax><literal>on</literal> | <literal>off</literal></syntax>
892
<default>off</default>
893
<context>http</context>
894
<context>server</context>
895
<context>location</context>
896
<appeared-in>1.7.7</appeared-in>
897
898
<para>
899
Enables byte-range support
900
for both cached and uncached responses from the FastCGI server
901
regardless of the <header>Accept-Ranges</header> field in these responses.
902
</para>
903
904
</directive>
905
906
907
<directive name="fastcgi_hide_header">
908
<syntax><value>field</value></syntax>
909
<default/>
910
<context>http</context>
911
<context>server</context>
912
<context>location</context>
913
914
<para>
915
By default,
916
nginx does not pass the header fields <header>Status</header> and
917
<header>X-Accel-...</header> from the response of a FastCGI
918
server to a client.
919
The <literal>fastcgi_hide_header</literal> directive sets additional fields
920
that will not be passed.
921
If, on the contrary, the passing of fields needs to be permitted,
922
the <link id="fastcgi_pass_header"/> directive can be used.
923
</para>
924
925
</directive>
926
927
928
<directive name="fastcgi_ignore_client_abort">
929
<syntax><literal>on</literal> | <literal>off</literal></syntax>
930
<default>off</default>
931
<context>http</context>
932
<context>server</context>
933
<context>location</context>
934
935
<para>
936
Determines whether the connection with a FastCGI server should be
937
closed when a client closes the connection without waiting
938
for a response.
939
</para>
940
941
</directive>
942
943
944
<directive name="fastcgi_ignore_headers">
945
<syntax><value>field</value> ...</syntax>
946
<default/>
947
<context>http</context>
948
<context>server</context>
949
<context>location</context>
950
951
<para>
952
Disables processing of certain response header fields from the FastCGI server.
953
The following fields can be ignored: <header>X-Accel-Redirect</header>,
954
<header>X-Accel-Expires</header>, <header>X-Accel-Limit-Rate</header> (1.1.6),
955
<header>X-Accel-Buffering</header> (1.1.6),
956
<header>X-Accel-Charset</header> (1.1.6), <header>Expires</header>,
957
<header>Cache-Control</header>, <header>Set-Cookie</header> (0.8.44),
958
and <header>Vary</header> (1.7.7).
959
</para>
960
961
<para>
962
If not disabled, processing of these header fields has the following
963
effect:
964
<list type="bullet" compact="no">
965
966
<listitem>
967
<header>X-Accel-Expires</header>, <header>Expires</header>,
968
<header>Cache-Control</header>, <header>Set-Cookie</header>,
969
and <header>Vary</header>
970
set the parameters of response <link id="fastcgi_cache_valid">caching</link>;
971
</listitem>
972
973
<listitem>
974
<header>X-Accel-Redirect</header> performs an
975
<link doc="ngx_http_core_module.xml" id="internal">internal
976
redirect</link> to the specified URI;
977
</listitem>
978
979
<listitem>
980
<header>X-Accel-Limit-Rate</header> sets the
981
<link doc="ngx_http_core_module.xml" id="limit_rate">rate
982
limit</link> for transmission of a response to a client;
983
</listitem>
984
985
<listitem>
986
<header>X-Accel-Buffering</header> enables or disables
987
<link id="fastcgi_buffering">buffering</link> of a response;
988
</listitem>
989
990
<listitem>
991
<header>X-Accel-Charset</header> sets the desired
992
<link doc="ngx_http_charset_module.xml" id="charset"/>
993
of a response.
994
</listitem>
995
996
</list>
997
</para>
998
999
</directive>
1000
1001
1002
<directive name="fastcgi_index">
1003
<syntax><value>name</value></syntax>
1004
<default/>
1005
<context>http</context>
1006
<context>server</context>
1007
<context>location</context>
1008
1009
<para>
1010
Sets a file name that will be appended after a URI that ends with
1011
a slash, in the value of the <var>$fastcgi_script_name</var> variable.
1012
For example, with these settings
1013
<example>
1014
fastcgi_index index.php;
1015
fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
1016
</example>
1017
and the “<literal>/page.php</literal>” request,
1018
the <literal>SCRIPT_FILENAME</literal> parameter will be equal to
1019
<literal>/home/www/scripts/php/page.php</literal>”,
1020
and with the “<literal>/</literal>” request it will be equal to
1021
<literal>/home/www/scripts/php/index.php</literal>”.
1022
</para>
1023
1024
</directive>
1025
1026
1027
<directive name="fastcgi_intercept_errors">
1028
<syntax><literal>on</literal> | <literal>off</literal></syntax>
1029
<default>off</default>
1030
<context>http</context>
1031
<context>server</context>
1032
<context>location</context>
1033
1034
<para>
1035
Determines whether FastCGI server responses with codes greater than or equal
1036
to 300 should be passed to a client
1037
or be intercepted and redirected to nginx for processing
1038
with the <link doc="ngx_http_core_module.xml" id="error_page"/> directive.
1039
</para>
1040
1041
</directive>
1042
1043
1044
<directive name="fastcgi_keep_conn">
1045
<syntax><literal>on</literal> | <literal>off</literal></syntax>
1046
<default>off</default>
1047
<context>http</context>
1048
<context>server</context>
1049
<context>location</context>
1050
<appeared-in>1.1.4</appeared-in>
1051
1052
<para>
1053
By default, a FastCGI server will close a connection right after
1054
sending the response.
1055
However, when this directive is set to the value <literal>on</literal>,
1056
nginx will instruct a FastCGI server to keep connections open.
1057
This is necessary, in particular, for
1058
<link doc="ngx_http_upstream_module.xml" id="keepalive"/>
1059
connections to FastCGI servers to function.
1060
</para>
1061
1062
</directive>
1063
1064
1065
<directive name="fastcgi_limit_rate">
1066
<syntax><value>rate</value></syntax>
1067
<default>0</default>
1068
<context>http</context>
1069
<context>server</context>
1070
<context>location</context>
1071
<appeared-in>1.7.7</appeared-in>
1072
1073
<para>
1074
Limits the speed of reading the response from the FastCGI server.
1075
The <value>rate</value> is specified in bytes per second.
1076
The zero value disables rate limiting.
1077
The limit is set per a request, and so if nginx simultaneously opens
1078
two connections to the FastCFI server,
1079
the overall rate will be twice as much as the specified limit.
1080
The limitation works only if
1081
<link id="fastcgi_buffering">buffering</link> of responses from the FastCGI
1082
server is enabled.
1083
Parameter value can contain variables (1.27.0).
1084
</para>
1085
1086
</directive>
1087
1088
1089
<directive name="fastcgi_max_temp_file_size">
1090
<syntax><value>size</value></syntax>
1091
<default>1024m</default>
1092
<context>http</context>
1093
<context>server</context>
1094
<context>location</context>
1095
1096
<para>
1097
When <link id="fastcgi_buffering">buffering</link> of responses from the FastCGI
1098
server is enabled, and the whole response does not fit into the buffers
1099
set by the <link id="fastcgi_buffer_size"/> and <link id="fastcgi_buffers"/>
1100
directives, a part of the response can be saved to a temporary file.
1101
This directive sets the maximum <value>size</value> of the temporary file.
1102
The size of data written to the temporary file at a time is set
1103
by the <link id="fastcgi_temp_file_write_size"/> directive.
1104
</para>
1105
1106
<para>
1107
The zero value disables buffering of responses to temporary files.
1108
</para>
1109
1110
<para>
1111
<note>
1112
This restriction does not apply to responses
1113
that will be <link id="fastcgi_cache">cached</link>
1114
or <link id="fastcgi_store">stored</link> on disk.
1115
</note>
1116
</para>
1117
1118
</directive>
1119
1120
1121
<directive name="fastcgi_next_upstream">
1122
<syntax>
1123
<literal>error</literal> |
1124
<literal>timeout</literal> |
1125
<literal>denied</literal> |
1126
<literal>invalid_header</literal> |
1127
<literal>http_500</literal> |
1128
<literal>http_503</literal> |
1129
<literal>http_403</literal> |
1130
<literal>http_404</literal> |
1131
<literal>http_429</literal> |
1132
<literal>non_idempotent</literal> |
1133
<literal>off</literal>
1134
...</syntax>
1135
<default>error timeout</default>
1136
<context>http</context>
1137
<context>server</context>
1138
<context>location</context>
1139
1140
<para>
1141
Specifies in which cases a request should be passed to the next server:
1142
<list type="tag">
1143
1144
<tag-name><literal>error</literal></tag-name>
1145
<tag-desc>an error occurred while establishing a connection with the
1146
server, passing a request to it, or reading the response header;</tag-desc>
1147
1148
<tag-name><literal>timeout</literal></tag-name>
1149
<tag-desc>a timeout has occurred while establishing a connection with the
1150
server, passing a request to it, or reading the response header;</tag-desc>
1151
1152
<tag-name id="denied"><literal>denied</literal></tag-name>
1153
<tag-desc>the server <link id="fastcgi_allow_upstream">denied</link>
1154
the connection (1.29.3);
1155
<para>
1156
<note>
1157
This parameter is available as part of our
1158
<commercial_version>commercial subscription</commercial_version>.
1159
</note>
1160
</para>
1161
</tag-desc>
1162
1163
<tag-name id="invalid_header"><literal>invalid_header</literal></tag-name>
1164
<tag-desc>a server returned an empty or invalid response;</tag-desc>
1165
1166
<tag-name><literal>http_500</literal></tag-name>
1167
<tag-desc>a server returned a response with the code 500;</tag-desc>
1168
1169
<tag-name><literal>http_503</literal></tag-name>
1170
<tag-desc>a server returned a response with the code 503;</tag-desc>
1171
1172
<tag-name><literal>http_403</literal></tag-name>
1173
<tag-desc>a server returned a response with the code 403;</tag-desc>
1174
1175
<tag-name><literal>http_404</literal></tag-name>
1176
<tag-desc>a server returned a response with the code 404;</tag-desc>
1177
1178
<tag-name><literal>http_429</literal></tag-name>
1179
<tag-desc>a server returned a response with the code 429 (1.11.13);</tag-desc>
1180
1181
<tag-name id="non_idempotent"><literal>non_idempotent</literal></tag-name>
1182
<tag-desc>normally, requests with a
1183
<link url="https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.2">non-idempotent</link>
1184
method
1185
(<literal>POST</literal>, <literal>LOCK</literal>, <literal>PATCH</literal>)
1186
are not passed to the next server
1187
if a request has been sent to an upstream server (1.9.13);
1188
enabling this option explicitly allows retrying such requests;
1189
</tag-desc>
1190
1191
<tag-name><literal>off</literal></tag-name>
1192
<tag-desc>disables passing a request to the next server.</tag-desc>
1193
1194
</list>
1195
</para>
1196
1197
<para>
1198
One should bear in mind that passing a request to the next server is
1199
only possible if nothing has been sent to a client yet.
1200
That is, if an error or timeout occurs in the middle of the
1201
transferring of a response, fixing this is impossible.
1202
</para>
1203
1204
<para>
1205
The directive also defines what is considered an
1206
<link doc="ngx_http_upstream_module.xml" id="max_fails">unsuccessful
1207
attempt</link> of communication with a server.
1208
The cases of <literal>error</literal>, <literal>timeout</literal>,
1209
<literal>denied</literal> and
1210
<literal>invalid_header</literal> are always considered unsuccessful attempts,
1211
even if they are not specified in the directive.
1212
The cases of <literal>http_500</literal>, <literal>http_503</literal>,
1213
and <literal>http_429</literal> are
1214
considered unsuccessful attempts only if they are specified in the directive.
1215
The cases of <literal>http_403</literal> and <literal>http_404</literal>
1216
are never considered unsuccessful attempts.
1217
</para>
1218
1219
<para>
1220
Passing a request to the next server can be limited by
1221
<link id="fastcgi_next_upstream_tries">the number of tries</link>
1222
and by <link id="fastcgi_next_upstream_timeout">time</link>.
1223
</para>
1224
1225
</directive>
1226
1227
1228
<directive name="fastcgi_next_upstream_timeout">
1229
<syntax><value>time</value></syntax>
1230
<default>0</default>
1231
<context>http</context>
1232
<context>server</context>
1233
<context>location</context>
1234
<appeared-in>1.7.5</appeared-in>
1235
1236
<para>
1237
Limits the time during which a request can be passed to the
1238
<link id="fastcgi_next_upstream">next server</link>.
1239
The <literal>0</literal> value turns off this limitation.
1240
</para>
1241
1242
</directive>
1243
1244
1245
<directive name="fastcgi_next_upstream_tries">
1246
<syntax><value>number</value></syntax>
1247
<default>0</default>
1248
<context>http</context>
1249
<context>server</context>
1250
<context>location</context>
1251
<appeared-in>1.7.5</appeared-in>
1252
1253
<para>
1254
Limits the number of possible tries for passing a request to the
1255
<link id="fastcgi_next_upstream">next server</link>.
1256
The <literal>0</literal> value turns off this limitation.
1257
</para>
1258
1259
</directive>
1260
1261
1262
<directive name="fastcgi_no_cache">
1263
<syntax><value>string</value> ...</syntax>
1264
<default/>
1265
<context>http</context>
1266
<context>server</context>
1267
<context>location</context>
1268
1269
<para>
1270
Defines conditions under which the response will not be saved to a cache.
1271
If at least one value of the string parameters is not empty and is not
1272
equal to “0” then the response will not be saved:
1273
<example>
1274
fastcgi_no_cache $cookie_nocache $arg_nocache$arg_comment;
1275
fastcgi_no_cache $http_pragma $http_authorization;
1276
</example>
1277
Can be used along with the <link id="fastcgi_cache_bypass"/> directive.
1278
</para>
1279
1280
</directive>
1281
1282
1283
<directive name="fastcgi_param">
1284
<syntax>
1285
<value>parameter</value> <value>value</value>
1286
[<literal>if_not_empty</literal>]</syntax>
1287
<default>HTTP_HOST $host$is_request_port$request_port</default>
1288
<context>http</context>
1289
<context>server</context>
1290
<context>location</context>
1291
1292
<para>
1293
Sets a <value>parameter</value> that should be passed to the FastCGI server.
1294
The <value>value</value> can contain text, variables, and their combination.
1295
These directives are inherited from the previous configuration level
1296
if and only if there are no <literal>fastcgi_param</literal> directives
1297
defined on the current level.
1298
</para>
1299
1300
<para>
1301
The following example shows the minimum required settings for PHP:
1302
<example>
1303
fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
1304
fastcgi_param QUERY_STRING $query_string;
1305
</example>
1306
</para>
1307
1308
<para>
1309
The <literal>SCRIPT_FILENAME</literal> parameter is used in PHP for
1310
determining the script name, and the <literal>QUERY_STRING</literal>
1311
parameter is used to pass request parameters.
1312
</para>
1313
1314
<para>
1315
For scripts that process <literal>POST</literal> requests, the
1316
following three parameters are also required:
1317
<example>
1318
fastcgi_param REQUEST_METHOD $request_method;
1319
fastcgi_param CONTENT_TYPE $content_type;
1320
fastcgi_param CONTENT_LENGTH $content_length;
1321
</example>
1322
</para>
1323
1324
<para>
1325
If PHP was built with the <literal>--enable-force-cgi-redirect</literal>
1326
configuration parameter, the <literal>REDIRECT_STATUS</literal> parameter
1327
should also be passed with the value “200”:
1328
<example>
1329
fastcgi_param REDIRECT_STATUS 200;
1330
</example>
1331
</para>
1332
1333
<para>
1334
If the directive is specified with <literal>if_not_empty</literal> (1.1.11) then
1335
such a parameter will be passed to the server only if its value is not empty:
1336
<example>
1337
fastcgi_param HTTPS $https if_not_empty;
1338
</example>
1339
</para>
1340
1341
</directive>
1342
1343
1344
<directive name="fastcgi_pass">
1345
<syntax><value>address</value></syntax>
1346
<default/>
1347
<context>location</context>
1348
<context>if in location</context>
1349
1350
<para>
1351
Sets the address of a FastCGI server.
1352
The address can be specified as a domain name or IP address,
1353
and a port:
1354
<example>
1355
fastcgi_pass localhost:9000;
1356
</example>
1357
or as a UNIX-domain socket path:
1358
<example>
1359
fastcgi_pass unix:/tmp/fastcgi.socket;
1360
</example>
1361
</para>
1362
1363
<para>
1364
If a domain name resolves to several addresses, all of them will be
1365
used in a round-robin fashion.
1366
In addition, an address can be specified as a
1367
<link doc="ngx_http_upstream_module.xml">server group</link>.
1368
</para>
1369
1370
<para>
1371
Parameter value can contain variables.
1372
In this case, if an address is specified as a domain name,
1373
the name is searched among the described
1374
<link doc="ngx_http_upstream_module.xml">server groups</link>,
1375
and, if not found, is determined using a
1376
<link doc="ngx_http_core_module.xml" id="resolver"/>.
1377
</para>
1378
1379
</directive>
1380
1381
1382
<directive name="fastcgi_pass_header">
1383
<syntax><value>field</value></syntax>
1384
<default/>
1385
<context>http</context>
1386
<context>server</context>
1387
<context>location</context>
1388
1389
<para>
1390
Permits passing <link id="fastcgi_hide_header">otherwise disabled</link> header
1391
fields from a FastCGI server to a client.
1392
</para>
1393
1394
</directive>
1395
1396
1397
<directive name="fastcgi_pass_request_body">
1398
<syntax><literal>on</literal> | <literal>off</literal></syntax>
1399
<default>on</default>
1400
<context>http</context>
1401
<context>server</context>
1402
<context>location</context>
1403
1404
<para>
1405
Indicates whether the original request body is passed
1406
to the FastCGI server.
1407
See also the <link id="fastcgi_pass_request_headers"/> directive.
1408
</para>
1409
1410
</directive>
1411
1412
1413
<directive name="fastcgi_pass_request_headers">
1414
<syntax><literal>on</literal> | <literal>off</literal></syntax>
1415
<default>on</default>
1416
<context>http</context>
1417
<context>server</context>
1418
<context>location</context>
1419
1420
<para>
1421
Indicates whether the header fields of the original request are passed
1422
to the FastCGI server.
1423
See also the <link id="fastcgi_pass_request_body"/> directive.
1424
</para>
1425
1426
</directive>
1427
1428
1429
<directive name="fastcgi_read_timeout">
1430
<syntax><value>time</value></syntax>
1431
<default>60s</default>
1432
<context>http</context>
1433
<context>server</context>
1434
<context>location</context>
1435
1436
<para>
1437
Defines a timeout for reading a response from the FastCGI server.
1438
The timeout is set only between two successive read operations,
1439
not for the transmission of the whole response.
1440
If the FastCGI server does not transmit anything within this time,
1441
the connection is closed.
1442
</para>
1443
1444
</directive>
1445
1446
1447
<directive name="fastcgi_request_buffering">
1448
<syntax><literal>on</literal> | <literal>off</literal></syntax>
1449
<default>on</default>
1450
<context>http</context>
1451
<context>server</context>
1452
<context>location</context>
1453
<appeared-in>1.7.11</appeared-in>
1454
1455
<para>
1456
Enables or disables buffering of a client request body.
1457
</para>
1458
1459
<para>
1460
When buffering is enabled, the entire request body is
1461
<link doc="ngx_http_core_module.xml" id="client_body_buffer_size">read</link>
1462
from the client before sending the request to a FastCGI server.
1463
</para>
1464
1465
<para>
1466
When buffering is disabled, the request body is sent to the FastCGI server
1467
immediately as it is received.
1468
In this case, the request cannot be passed to the
1469
<link id="fastcgi_next_upstream">next server</link>
1470
if nginx already started sending the request body.
1471
</para>
1472
1473
</directive>
1474
1475
1476
<directive name="fastcgi_request_dynamic">
1477
<syntax><literal>on</literal> | <literal>off</literal></syntax>
1478
<default>off</default>
1479
<context>http</context>
1480
<context>server</context>
1481
<context>location</context>
1482
<appeared-in>1.29.3</appeared-in>
1483
1484
<para>
1485
Enables or disables creation of a separate request instance
1486
for each FastCGI server.
1487
By default, a single request is used for all FastCGI servers.
1488
If enabled, a separate request instance is created,
1489
allowing per-server request customization.
1490
</para>
1491
1492
<para>
1493
<note>
1494
This directive is available as part of our
1495
<commercial_version>commercial subscription</commercial_version>.
1496
</note>
1497
</para>
1498
1499
</directive>
1500
1501
1502
<directive name="fastcgi_send_lowat">
1503
<syntax><value>size</value></syntax>
1504
<default>0</default>
1505
<context>http</context>
1506
<context>server</context>
1507
<context>location</context>
1508
1509
<para>
1510
If the directive is set to a non-zero value, nginx will try to
1511
minimize the number
1512
of send operations on outgoing connections to a FastCGI server by using either
1513
<c-def>NOTE_LOWAT</c-def> flag of the
1514
<link doc="../events.xml" id="kqueue"/> method,
1515
or the <c-def>SO_SNDLOWAT</c-def> socket option,
1516
with the specified <value>size</value>.
1517
</para>
1518
1519
<para>
1520
This directive is ignored on Linux, Solaris, and Windows.
1521
</para>
1522
1523
</directive>
1524
1525
1526
<directive name="fastcgi_send_timeout">
1527
<syntax><value>time</value></syntax>
1528
<default>60s</default>
1529
<context>http</context>
1530
<context>server</context>
1531
<context>location</context>
1532
1533
<para>
1534
Sets a timeout for transmitting a request to the FastCGI server.
1535
The timeout is set only between two successive write operations,
1536
not for the transmission of the whole request.
1537
If the FastCGI server does not receive anything within this time,
1538
the connection is closed.
1539
</para>
1540
1541
</directive>
1542
1543
1544
<directive name="fastcgi_socket_keepalive">
1545
<syntax><literal>on</literal> | <literal>off</literal></syntax>
1546
<default>off</default>
1547
<context>http</context>
1548
<context>server</context>
1549
<context>location</context>
1550
<appeared-in>1.15.6</appeared-in>
1551
1552
<para>
1553
Configures the “TCP keepalive” behavior
1554
for outgoing connections to a FastCGI server.
1555
By default, the operating system’s settings are in effect for the socket.
1556
If the directive is set to the value “<literal>on</literal>”, the
1557
<c-def>SO_KEEPALIVE</c-def> socket option is turned on for the socket.
1558
</para>
1559
1560
</directive>
1561
1562
1563
<directive name="fastcgi_split_path_info">
1564
<syntax><value>regex</value></syntax>
1565
<default/>
1566
<context>location</context>
1567
1568
<para>
1569
Defines a regular expression that captures a value for the
1570
<var>$fastcgi_path_info</var> variable.
1571
The regular expression should have two captures: the first becomes
1572
a value of the <var>$fastcgi_script_name</var> variable, the second
1573
becomes a value of the <var>$fastcgi_path_info</var> variable.
1574
For example, with these settings
1575
<example>
1576
location ~ ^(.+\.php)(.*)$ {
1577
fastcgi_split_path_info ^(.+\.php)(.*)$;
1578
fastcgi_param SCRIPT_FILENAME /path/to/php$fastcgi_script_name;
1579
fastcgi_param PATH_INFO $fastcgi_path_info;
1580
</example>
1581
and the “<literal>/show.php/article/0001</literal>” request,
1582
the <literal>SCRIPT_FILENAME</literal> parameter will be equal to
1583
<literal>/path/to/php/show.php</literal>”, and the
1584
<literal>PATH_INFO</literal> parameter will be equal to
1585
<literal>/article/0001</literal>”.
1586
</para>
1587
1588
</directive>
1589
1590
1591
<directive name="fastcgi_store">
1592
<syntax>
1593
<literal>on</literal> |
1594
<literal>off</literal> |
1595
<value>string</value></syntax>
1596
<default>off</default>
1597
<context>http</context>
1598
<context>server</context>
1599
<context>location</context>
1600
1601
<para>
1602
Enables saving of files to a disk.
1603
The <literal>on</literal> parameter saves files with paths
1604
corresponding to the directives
1605
<link doc="ngx_http_core_module.xml" id="alias"/> or
1606
<link doc="ngx_http_core_module.xml" id="root"/>.
1607
The <literal>off</literal> parameter disables saving of files.
1608
In addition, the file name can be set explicitly using the
1609
<value>string</value> with variables:
1610
<example>
1611
fastcgi_store /data/www$original_uri;
1612
</example>
1613
</para>
1614
1615
<para>
1616
The modification time of files is set according to the received
1617
<header>Last-Modified</header> response header field.
1618
The response is first written to a temporary file,
1619
and then the file is renamed.
1620
Starting from version 0.8.9, temporary files and the persistent store
1621
can be put on different file systems.
1622
However, be aware that in this case a file is copied
1623
across two file systems instead of the cheap renaming operation.
1624
It is thus recommended that for any given location both saved files and a
1625
directory holding temporary files, set by the <link id="fastcgi_temp_path"/>
1626
directive, are put on the same file system.
1627
</para>
1628
1629
<para>
1630
This directive can be used to create local copies of static unchangeable
1631
files, e.g.:
1632
<example>
1633
location /images/ {
1634
root /data/www;
1635
error_page 404 = /fetch$uri;
1636
}
1637
1638
location /fetch/ {
1639
internal;
1640
1641
fastcgi_pass backend:9000;
1642
...
1643
1644
fastcgi_store on;
1645
fastcgi_store_access user:rw group:rw all:r;
1646
fastcgi_temp_path /data/temp;
1647
1648
alias /data/www/;
1649
}
1650
</example>
1651
</para>
1652
1653
</directive>
1654
1655
1656
<directive name="fastcgi_store_access">
1657
<syntax><value>users</value>:<value>permissions</value> ...</syntax>
1658
<default>user:rw</default>
1659
<context>http</context>
1660
<context>server</context>
1661
<context>location</context>
1662
1663
<para>
1664
Sets access permissions for newly created files and directories, e.g.:
1665
<example>
1666
fastcgi_store_access user:rw group:rw all:r;
1667
</example>
1668
</para>
1669
1670
<para>
1671
If any <literal>group</literal> or <literal>all</literal> access permissions
1672
are specified then <literal>user</literal> permissions may be omitted:
1673
<example>
1674
fastcgi_store_access group:rw all:r;
1675
</example>
1676
</para>
1677
1678
</directive>
1679
1680
1681
<directive name="fastcgi_temp_file_write_size">
1682
<syntax><value>size</value></syntax>
1683
<default>8k|16k</default>
1684
<context>http</context>
1685
<context>server</context>
1686
<context>location</context>
1687
1688
<para>
1689
Limits the <value>size</value> of data written to a temporary file
1690
at a time, when buffering of responses from the FastCGI server
1691
to temporary files is enabled.
1692
By default, <value>size</value> is limited by two buffers set by the
1693
<link id="fastcgi_buffer_size"/> and <link id="fastcgi_buffers"/> directives.
1694
The maximum size of a temporary file is set by the
1695
<link id="fastcgi_max_temp_file_size"/> directive.
1696
</para>
1697
1698
</directive>
1699
1700
1701
<directive name="fastcgi_temp_path">
1702
<syntax>
1703
<value>path</value>
1704
[<value>level1</value>
1705
[<value>level2</value>
1706
[<value>level3</value>]]]</syntax>
1707
<default>fastcgi_temp</default>
1708
<context>http</context>
1709
<context>server</context>
1710
<context>location</context>
1711
1712
<para>
1713
Defines a directory for storing temporary files
1714
with data received from FastCGI servers.
1715
Up to three-level subdirectory hierarchy can be used underneath the specified
1716
directory.
1717
For example, in the following configuration
1718
<example>
1719
fastcgi_temp_path /spool/nginx/fastcgi_temp 1 2;
1720
</example>
1721
a temporary file might look like this:
1722
<example>
1723
/spool/nginx/fastcgi_temp/<emphasis>7</emphasis>/<emphasis>45</emphasis>/00000123<emphasis>457</emphasis>
1724
</example>
1725
</para>
1726
1727
<para>
1728
See also the <literal>use_temp_path</literal> parameter of the
1729
<link id="fastcgi_cache_path"/> directive.
1730
</para>
1731
1732
</directive>
1733
1734
</section>
1735
1736
1737
<section id="parameters" name="Parameters Passed to a FastCGI Server">
1738
1739
<para>
1740
HTTP request header fields are passed to a FastCGI server as parameters.
1741
In applications and scripts running as FastCGI servers,
1742
these parameters are usually made available as environment variables.
1743
For example, the <header>User-Agent</header> header field is passed as the
1744
<literal>HTTP_USER_AGENT</literal> parameter.
1745
In addition to HTTP request header fields, it is possible to pass arbitrary
1746
parameters using the <link id="fastcgi_param"/> directive.
1747
</para>
1748
1749
</section>
1750
1751
1752
<section id="variables" name="Embedded Variables">
1753
1754
<para>
1755
The <literal>ngx_http_fastcgi_module</literal> module supports embedded
1756
variables that can be used to set parameters using the
1757
<link id="fastcgi_param"/> directive:
1758
<list type="tag">
1759
1760
<tag-name id="var_fastcgi_script_name"><var>$fastcgi_script_name</var>
1761
</tag-name>
1762
<tag-desc>
1763
request URI or, if a URI ends with a slash, request URI with an index file
1764
name configured by the <link id="fastcgi_index"/> directive appended to it.
1765
This variable can be used to set the
1766
<literal>SCRIPT_FILENAME</literal> and <literal>PATH_TRANSLATED</literal>
1767
parameters that determine the script name in PHP.
1768
For example, for the “<literal>/info/</literal>” request with the
1769
following directives
1770
<example>
1771
fastcgi_index index.php;
1772
fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
1773
</example>
1774
the <literal>SCRIPT_FILENAME</literal> parameter will be equal to
1775
<literal>/home/www/scripts/php/info/index.php</literal>”.
1776
1777
<para>
1778
When using the <link id="fastcgi_split_path_info"/> directive,
1779
the <var>$fastcgi_script_name</var> variable equals the value of
1780
the first capture set by the directive.
1781
</para>
1782
</tag-desc>
1783
1784
<tag-name id="var_fastcgi_path_info"><var>$fastcgi_path_info</var></tag-name>
1785
<tag-desc>the value of the second capture set by the
1786
<link id="fastcgi_split_path_info"/> directive.
1787
This variable can be used to set the
1788
<literal>PATH_INFO</literal> parameter.
1789
</tag-desc>
1790
1791
</list>
1792
</para>
1793
1794
</section>
1795
1796
</module>
1797
1798