Fastcgi_read_timeout

/ Comments off
  1. Fastcgi_read_timeout Php-fpm
  2. Fastcgi_read_timeout
  3. Fastcgi Protocol
  4. Iis 10 Fastcgi
  5. Fastcgi_read_timeout
  6. Fastcgi_read_timeout Php
  7. Fastcgi_read_timeout Apache

It is very common to see a 504 Gateway Timeout error using Nginx webserver. This timeout error is generated often by a number of reasons on the backend connection that is serving content. To fix 504 Gateway Time-out, you will have to figure out what configuration are you using.

Keepalivetimeout 125; proxyreadtimeout 125; proxyconnecttimeout 125; fastcgireadtimeout 125; This fixed the issue some of the time, but intermittently I would get the MySQL 'MySQL server has gone away' error, which required one more tweak: /etc/my.conf. Waittimeout = 120. It is very common to see a 504 Gateway Timeout error using Nginx webserver. This timeout error is generated often by a number of reasons. Sep 25, 2012 Have you see this where you receive a HTTP 499 response from NginX rather than a 504? I’m having that problem with an AWS instance where I have a PHP script which terminates after 60 seconds.

App

How you might see the 504 Gateway Timeout error

Different websites may customize the 504 gateway timeout error message. Here are the most common 504 error messages:

  • “504 Gateway Timeout”
  • “504 Gateway Time-Out”
  • “504 Gateway Timeout NGINX”
  • “Nginx 504 Gateway Timeout”
  • “HTTP 504 Gateway Timeout”
  • “HTTP 504 Error”
  • “HTTP 504”
  • “Gateway Timeout (504)”

504 Gateway Timeout error on Nginx + FastCGI (php-fpm)

For Nginx + (php-fpm), you should try to tweak nginx configuration in this way:

Try raising max_execution_time setting in php.ini file (CentOS path is /etc/php.ini):

Fastcgi_read_timeout Php-fpm

But, you should also change set request_terminate_timeout parameter (commented by default) at http://www.conf file from PHP-FPM:

Then set the variable to the same value as max_execution_time:

Now let’s add fastcgi_read_timeout variable inside our Nginx virtual host configuration:

Then restart nginx:

504 Gateway Timeout error using Nginx as Proxy

For Nginx as Proxy for Apache web server, this is what you have to try to fix the 504 Gateway Timeout error:

Add these variables to nginx.conf file:

Then restart nginx:

Module ngx_http_fastcgi_module

Example Configuration
Directives
fastcgi_bind
fastcgi_buffer_size
fastcgi_buffering
fastcgi_buffers
fastcgi_busy_buffers_size
fastcgi_cache
fastcgi_cache_background_update
fastcgi_cache_bypass
fastcgi_cache_key
fastcgi_cache_lock
fastcgi_cache_lock_age
fastcgi_cache_lock_timeout
fastcgi_cache_max_range_offset
fastcgi_cache_methods
fastcgi_cache_min_uses
fastcgi_cache_path
fastcgi_cache_purge
fastcgi_cache_revalidate
fastcgi_cache_use_stale
fastcgi_cache_valid
fastcgi_catch_stderr
fastcgi_connect_timeout
fastcgi_force_ranges
fastcgi_hide_header
fastcgi_ignore_client_abort
fastcgi_ignore_headers
fastcgi_index
fastcgi_intercept_errors
fastcgi_keep_conn
fastcgi_limit_rate
fastcgi_max_temp_file_size
fastcgi_next_upstream
fastcgi_next_upstream_timeout
fastcgi_next_upstream_tries
fastcgi_no_cache
fastcgi_param
fastcgi_pass
fastcgi_pass_header
fastcgi_pass_request_body
fastcgi_pass_request_headers
fastcgi_read_timeout
fastcgi_request_buffering
fastcgi_send_lowat
fastcgi_send_timeout
fastcgi_socket_keepalive
fastcgi_split_path_info
fastcgi_store
fastcgi_store_access
fastcgi_temp_file_write_size
fastcgi_temp_path
Parameters Passed to a FastCGI Server
Embedded Variables

The ngx_http_fastcgi_module module allows passingrequests to a FastCGI server.

Example Configuration

Directives

Syntax: fastcgi_bindaddress [transparent] off;
Default:
Context: http, server, location

This directive appeared in version 0.8.22.

Makes outgoing connections to a FastCGI server originatefrom the specified local IP address with an optional port (1.11.2).Parameter value can contain variables (1.3.12).The special value off (1.3.12) cancels the effectof the fastcgi_bind directiveinherited from the previous configuration level, which allows thesystem to auto-assign the local IP address and port.

The transparent parameter (1.11.0) allowsoutgoing connections to a FastCGI server originatefrom a non-local IP address,for example, from a real IP address of a client:

In order for this parameter to work,it is usually necessary to run nginx worker processes with thesuperuser privileges.On Linux it is not required (1.13.8) as ifthe transparent parameter is specified, worker processesinherit the CAP_NET_RAW capability from the master process.It is also necessary to configure kernel routing tableto intercept network traffic from the FastCGI server.

Syntax: fastcgi_buffer_sizesize;
Default:
Context: http, server, location

Sets the size of the buffer used for reading the first partof the response received from the FastCGI server.This part usually contains a small response header.By default, the buffer size is equal to one memory page.This is either 4K or 8K, depending on a platform.It can be made smaller, however.

Syntax: fastcgi_bufferingonoff;
Default:
Context: http, server, location

This directive appeared in version 1.5.6.

Enables or disables buffering of responses from the FastCGI server.

When buffering is enabled, nginx receives a response from the FastCGI serveras soon as possible, saving it into the buffers set by thefastcgi_buffer_size and fastcgi_buffers directives.If the whole response does not fit into memory, a part of it can be savedto a temporary file on the disk.Writing to temporary files is controlled by thefastcgi_max_temp_file_size andfastcgi_temp_file_write_size directives.

When buffering is disabled, the 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 serverat a time is set by the fastcgi_buffer_size directive.

Buffering can also be enabled or disabled by passing“yes” or “no” in the“X-Accel-Buffering” response header field.This capability can be disabled using thefastcgi_ignore_headers directive.

Syntax: fastcgi_buffersnumbersize;
Default:
Context: http, server, location

Sets the number and size of thebuffers 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.

Syntax: fastcgi_busy_buffers_sizesize;
Default:
Context: http, server, location

When buffering of responses from the FastCGIserver is enabled, limits the total size of buffers thatcan be busy sending a response to the client while the response is notyet fully read.In the meantime, the rest of the buffers can be used for reading the responseand, if needed, buffering part of the response to a temporary file.By default, size is limited by the size of two buffers set by thefastcgi_buffer_size and fastcgi_buffers directives.

Syntax: fastcgi_cachezoneoff;
Default:
Context: http, server, location

Defines a shared memory zone used for caching.The same zone can be used in several places.Parameter value can contain variables (1.7.9).The off parameter disables caching inheritedfrom the previous configuration level.

Syntax: fastcgi_cache_background_updateonoff;
Default:
Context: http, server, location

This directive appeared in version 1.11.10.

Allows starting a background subrequestto update an expired cache item,while a stale cached response is returned to the client.Note that it is necessary toallowthe usage of a stale cached response when it is being updated.

Syntax: fastcgi_cache_bypassstring ..;
Default:
Context: http, server, location

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 notequal to “0” then the response will not be taken from the cache:

Can be used along with the fastcgi_no_cache directive.

Syntax: fastcgi_cache_keystring;
Default:
Context: http, server, location

Defines a key for caching, for example

Syntax: fastcgi_cache_lockonoff;
Default:
Context: http, server, location

This directive appeared in version 1.1.12.

When enabled, only one request at a time will be allowed to populatea new cache element identified according to the fastcgi_cache_keydirective by passing a request to a FastCGI server.Other requests of the same cache element will either waitfor a response to appear in the cache or the cache lock forthis element to be released, up to the time set by thefastcgi_cache_lock_timeout directive.

Syntax: fastcgi_cache_lock_agetime;
Default:
Context: http, server, location

This directive appeared in version 1.7.8.

If the last request passed to the FastCGI serverfor populating a new cache elementhas not completed for the specified time,one more request may be passed to the FastCGI server.

Syntax: fastcgi_cache_lock_timeouttime;
Default:
Context: http, server, location

This directive appeared in version 1.1.12.

Sets a timeout for fastcgi_cache_lock.When the time expires,the request will be passed to the FastCGI server,however, the response will not be cached.

Before 1.7.8, the response could be cached.
Syntax: fastcgi_cache_max_range_offsetnumber;
Default:
Context: http, server, location

This directive appeared in version 1.11.6.

Sets an offset in bytes for byte-range requests.If the range is beyond the offset,the range request will be passed to the FastCGI serverand the response will not be cached.

Fastcgi_read_timeout
Syntax: fastcgi_cache_methodsGETHEADPOST ..;
Default:
Context: http, server, location

This directive appeared in version 0.7.59.

If the client request method is listed in this directive thenthe response will be cached.“GET” and “HEAD” methods are alwaysadded to the list, though it is recommended to specify them explicitly.See also the fastcgi_no_cache directive.

Syntax: fastcgi_cache_min_usesnumber;
Default:
Context: http, server, location

Sets the number of requests after which the responsewill be cached.

Syntax: fastcgi_cache_pathpath [levels=levels] [use_temp_path=onoff] keys_zone=name:size [inactive=time] [max_size=size] [min_free=size] [manager_files=number] [manager_sleep=time] [manager_threshold=time] [loader_files=number] [loader_sleep=time] [loader_threshold=time] [purger=onoff] [purger_files=number] [purger_sleep=time] [purger_threshold=time];
Default:
Context: http

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 ofapplying the MD5 function to the proxied URL.The levels parameter defines hierarchy levels of a cache:from 1 to 3, each level accepts values 1 or 2.For example, in the following configuration

file names in a cache will look like this:

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 ondifferent file systems.However, be aware that in this case a file is copiedacross two file systems instead of the cheap renaming operation.It is thus recommended that for any given location both cache and a directoryholding temporary filesare put on the same file system.A directory for temporary files is set based onthe use_temp_path parameter (1.7.10).If this parameter is omitted or set to the value on,the directory set by the fastcgi_temp_path directivefor the given location will be used.If the value is set to off,temporary files will be put directly in the cache directory.

In addition, all active keys and information about data are storedin a shared memory zone, whose name and sizeare configured by the keys_zone parameter.One megabyte zone can store about 8 thousand keys.

As part ofcommercial subscription,the shared memory zone also stores extendedcache information,thus, it is required to specify a larger zone size for the same number of keys.For example,one megabyte zone can store about 4 thousand keys.

Cached data that are not accessed during the time specified by theinactive parameter get removed from the cacheregardless of their freshness.By default, inactive is set to 10 minutes.

The special “cache manager” process monitors the maximum cache size setby the max_size parameter,and the minimum amount of free space setby the min_free (1.19.1) parameteron the file system with cache.When the size is exceeded or there is not enough free space,it removes the least recently used data.The data is removed in iterations configured bymanager_files,manager_threshold, andmanager_sleep parameters (1.11.5).During one iteration no more than manager_files itemsare deleted (by default, 100).The duration of one iteration is limited by themanager_threshold parameter (by default, 200 milliseconds).Between iterations, a pause configured by the manager_sleepparameter (by default, 50 milliseconds) is made.

A minute after the start the special “cache loader” process is activated.It loads information about previously cached data stored on file systeminto a cache zone.The loading is also done in iterations.During one iteration no more than loader_files itemsare loaded (by default, 100).Besides, the duration of one iteration is limited by theloader_threshold parameter (by default, 200 milliseconds).Between iterations, a pause configured by the loader_sleepparameter (by default, 50 milliseconds) is made.

Additionally,the following parameters are available as part of ourcommercial subscription:

purger=onoff
Instructs whether cache entries that match awildcard keywill be removed from the disk by the cache purger (1.7.12).Setting the parameter to on(default is off)will activate the “cache purger” process thatpermanently iterates through all cache entriesand deletes the entries that match the wildcard key.
purger_files=number
Sets the number of items that will be scanned during one iteration (1.7.12).By default, purger_files is set to 10.
purger_threshold=number
Sets the duration of one iteration (1.7.12).By default, purger_threshold is set to 50 milliseconds.
purger_sleep=number
Sets a pause between iterations (1.7.12).By default, purger_sleep is set to 50 milliseconds.
In versions 1.7.3, 1.7.7, and 1.11.10 cache header format has been changed.Previously cached responses will be considered invalidafter upgrading to a newer nginx version.
Syntax: fastcgi_cache_purge string ..;
Default:
Context: http, server, location

This directive appeared in version 1.5.7.

Defines conditions under which the request will be considered a cachepurge request.If at least one value of the string parameters is not empty and is not equalto “0” then the cache entry with a correspondingcache key is removed.The result of successful operation is indicated by returningthe 204 (No Content) response.

If the cache key of a purge request endswith an asterisk (“*”), all cache entries matching thewildcard key will be removed from the cache.However, these entries will remain on the disk until they are deletedfor either inactivity,or processed by the cache purger (1.7.12),or a client attempts to access them.

Example configuration:

This functionality is available as part of ourcommercial subscription.
Syntax: fastcgi_cache_revalidateonoff;
Default:
Context: http, server, location

This directive appeared in version 1.5.7.

Enables revalidation of expired cache items using conditional requests withthe “If-Modified-Since” and “If-None-Match”header fields.

Syntax: fastcgi_cache_use_staleerrortimeoutinvalid_headerupdatinghttp_500http_503http_403http_404http_429off ..;
Default:
Context: http, server, location

Determines in which cases a stale cached response can be usedwhen an error occurs during communication with the FastCGI server.The directive’s parameters match the parameters of thefastcgi_next_upstream directive.

The error parameter also permitsusing a stale cached response if a FastCGI server to process a requestcannot be selected.

Additionally, the updating parameter permitsusing a stale cached response if it is currently being updated.This allows minimizing the number of accesses to FastCGI serverswhen updating cached data.

Using a stale cached responsecan also be enabled directly in the response headerfor a specified number of seconds after the response became stale (1.11.10).This has lower priority than using the directive parameters.

  • The“stale-while-revalidate”extension of the “Cache-Control” header field permitsusing a stale cached response if it is currently being updated.
  • The“stale-if-error”extension of the “Cache-Control” header field permitsusing a stale cached response in case of an error.

To minimize the number of accesses to FastCGI servers whenpopulating a new cache element, the fastcgi_cache_lockdirective can be used.

Syntax: fastcgi_cache_valid [code ..] time;
Default:
Context: http, server, location

Sets caching time for different response codes.For example, the following directives

set 10 minutes of caching for responses with codes 200 and 302and 1 minute for responses with code 404.

If only caching time is specified

then only 200, 301, and 302 responses are cached.

In addition, the any parameter can be specifiedto cache any responses:

Parameters of caching can also be set directlyin 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 aresponse in seconds.The zero value disables caching for a response.If the value starts with the @ prefix, it sets an absolutetime in seconds since Epoch, up to which the response may be cached.
  • If the header does not include the “X-Accel-Expires” field,parameters of caching may be set in the header fields“Expires” or “Cache-Control”.
  • If the header includes the “Set-Cookie” field, such aresponse will not be cached.
  • If the header includes the “Vary” fieldwith the special value “*”, such aresponse will not be cached (1.7.7).If the header includes the “Vary” fieldwith another value, such a response will be cachedtaking into account the corresponding request header fields (1.7.7).

Processing of one or more of these response header fields can be disabledusing the fastcgi_ignore_headers directive.

Syntax: fastcgi_catch_stderrstring;
Default:
Context: http, server, location

Sets a string to search for in the error stream of a responsereceived from a FastCGI server.If the string is found then it is considered that the FastCGIserver has returned an invalid response.This allows handling application errors in nginx, for example:

Syntax: fastcgi_connect_timeouttime;
Default:
Context: http, server, location

Defines a timeout for establishing a connection with a FastCGI server.It should be noted that this timeout cannot usually exceed 75 seconds.

Syntax: fastcgi_force_rangesonoff;
Default:
Context: http, server, location

This directive appeared in version 1.7.7.

Enables byte-range supportfor both cached and uncached responses from the FastCGI serverregardless of the “Accept-Ranges” field in these responses.

Syntax: fastcgi_hide_headerfield;
Default:
Context: http, server, location

By default,nginx does not pass the header fields “Status” and“X-Accel-..” from the response of a FastCGIserver to a client.The fastcgi_hide_header directive sets additional fieldsthat will not be passed.If, on the contrary, the passing of fields needs to be permitted,the fastcgi_pass_header directive can be used.

Syntax: fastcgi_ignore_client_abortonoff;
Default:
Context: http, server, location

Determines whether the connection with a FastCGI server should beclosed when a client closes the connection without waitingfor a response.

Syntax: fastcgi_ignore_headersfield ..;
Default:
Context: http, server, location

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”, “Set-Cookie” (0.8.44),and “Vary” (1.7.7).

If not disabled, processing of these header fields has the followingeffect:

  • “X-Accel-Expires”, “Expires”,“Cache-Control”, “Set-Cookie”,and “Vary”set the parameters of response caching;
  • “X-Accel-Redirect” performs aninternalredirect to the specified URI;
  • “X-Accel-Limit-Rate” sets theratelimit for transmission of a response to a client;
  • “X-Accel-Buffering” enables or disablesbuffering of a response;
  • “X-Accel-Charset” sets the desiredcharsetof a response.
Syntax: fastcgi_indexname;
Default:
Context: http, server, location

Sets a file name that will be appended after a URI that ends witha slash, in the value of the $fastcgi_script_name variable.For example, with these settings

and the “/page.php” request,the SCRIPT_FILENAME parameter will be equal to“/home/www/scripts/php/page.php”,and with the “/” request it will be equal to“/home/www/scripts/php/index.php”.

Syntax: fastcgi_intercept_errorsonoff;
Default:
Context: http, server, location

Determines whether FastCGI server responses with codes greater than or equalto 300 should be passed to a clientor be intercepted and redirected to nginx for processingwith the error_page directive.

Syntax: fastcgi_keep_connonoff;
Default:
Context: http, server, location

This directive appeared in version 1.1.4.

By default, a FastCGI server will close a connection right aftersending the response.However, when this directive is set to the value on,nginx will instruct a FastCGI server to keep connections open.This is necessary, in particular, forkeepaliveconnections to FastCGI servers to function.

Syntax: fastcgi_limit_raterate;
Default:
Context: http, server, location

This directive appeared in version 1.7.7.

Limits the speed of reading the response from the FastCGI server.The rate is specified in bytes per second.The zero value disables rate limiting.The limit is set per a request, and so if nginx simultaneously openstwo connections to the FastCFI server,the overall rate will be twice as much as the specified limit.The limitation works only ifbuffering of responses from the FastCGIserver is enabled.

Syntax: fastcgi_max_temp_file_sizesize;
Default:
Context: http, server, location

When buffering of responses from the FastCGIserver is enabled, and the whole response does not fit into the buffersset by the fastcgi_buffer_size and fastcgi_buffersdirectives, a part of the response can be saved to a temporary file.This directive sets the maximum size of the temporary file.The size of data written to the temporary file at a time is setby the fastcgi_temp_file_write_size directive.

The zero value disables buffering of responses to temporary files.

This restriction does not apply to responsesthat will be cachedor stored on disk.
Syntax: fastcgi_next_upstreamerrortimeoutinvalid_headerhttp_500http_503http_403http_404http_429non_idempotentoff ..;
Default:
Context: http, server, location

Specifies in which cases a request should be passed to the next server:

error
an error occurred while establishing a connection with theserver, passing a request to it, or reading the response header;
timeout
a timeout has occurred while establishing a connection with theserver, passing a request to it, or reading the response header;
invalid_header
a server returned an empty or invalid response;
http_500
a server returned a response with the code 500;
http_503
a server returned a response with the code 503;
http_403
a server returned a response with the code 403;
http_404
a server returned a response with the code 404;
http_429
a server returned a response with the code 429 (1.11.13);
non_idempotent
normally, requests with anon-idempotentmethod(POST, LOCK, PATCH)are not passed to the next serverif a request has been sent to an upstream server (1.9.13);enabling this option explicitly allows retrying such requests;
off
disables passing a request to the next server.

One should bear in mind that passing a request to the next server isonly possible if nothing has been sent to a client yet.That is, if an error or timeout occurs in the middle of thetransferring of a response, fixing this is impossible.

The directive also defines what is considered anunsuccessfulattempt of communication with a server.The cases of error, timeout andinvalid_header are always considered unsuccessful attempts,even if they are not specified in the directive.The cases of http_500, http_503,and http_429 areconsidered unsuccessful attempts only if they are specified in the directive.The cases of http_403 and http_404are never considered unsuccessful attempts.

Passing a request to the next server can be limited bythe number of triesand by time.

Syntax: fastcgi_next_upstream_timeouttime;
Default:
Context: http, server, location

This directive appeared in version 1.7.5.

Limits the time during which a request can be passed to thenext server.The 0 value turns off this limitation.

Syntax: fastcgi_next_upstream_triesnumber;
Default:
Context: http, server, location

This directive appeared in version 1.7.5.

Limits the number of possible tries for passing a request to thenext server.The 0 value turns off this limitation.

Syntax: fastcgi_no_cachestring ..;
Default:
Context: http, server, location

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 notequal to “0” then the response will not be saved:

Fastcgi_read_timeout

Can be used along with the fastcgi_cache_bypass directive.

Syntax: fastcgi_paramparametervalue [if_not_empty];
Default:
Context: http, server, location

Sets a parameter that should be passed to the FastCGI server.The value can contain text, variables, and their combination.These directives are inherited from the previous configuration levelif and only if there are no fastcgi_param directivesdefined on the current level.

The following example shows the minimum required settings for PHP:

The SCRIPT_FILENAME parameter is used in PHP fordetermining the script name, and the QUERY_STRINGparameter is used to pass request parameters.

For scripts that process POST requests, thefollowing three parameters are also required:

If PHP was built with the --enable-force-cgi-redirectconfiguration parameter, the REDIRECT_STATUS parametershould also be passed with the value “200”:

If the directive is specified with if_not_empty (1.1.11) thensuch a parameter will be passed to the server only if its value is not empty:

Syntax: fastcgi_passaddress;
Default:
Context: location, if in location

Sets the address of a FastCGI server.The address can be specified as a domain name or IP address,and a port:

or as a UNIX-domain socket path:

If a domain name resolves to several addresses, all of them will beused in a round-robin fashion.In addition, an address can be specified as aserver group.

Parameter value can contain variables.In this case, if an address is specified as a domain name,the name is searched among the describedserver groups,and, if not found, is determined using aresolver.

Syntax: fastcgi_pass_headerfield;
Default:
Context: http, server, location

Permits passing otherwise disabled headerfields from a FastCGI server to a client.

Syntax: fastcgi_pass_request_bodyonoff;
Default:
Context: http, server, location

Indicates whether the original request body is passedto the FastCGI server.See also the fastcgi_pass_request_headers directive.

Syntax: fastcgi_pass_request_headersonoff;
Default:
Context: http, server, location

Indicates whether the header fields of the original request are passedto the FastCGI server.See also the fastcgi_pass_request_body directive.

Syntax: fastcgi_read_timeouttime;
Default:
Context: http, server, location

Defines a timeout for reading a response from the FastCGI server.The timeout is set only between two successive read operations,not for the transmission of the whole response.If the FastCGI server does not transmit anything within this time,the connection is closed.

Syntax: fastcgi_request_bufferingonoff;
Default:
Context: http, server, location

This directive appeared in version 1.7.11.

Enables or disables buffering of a client request body.

When buffering is enabled, the entire request body isreadfrom the client before sending the request to a FastCGI server.

Fastcgi_read_timeout

When buffering is disabled, the request body is sent to the FastCGI serverimmediately as it is received.In this case, the request cannot be passed to thenext serverif nginx already started sending the request body.

Syntax: fastcgi_send_lowatsize;
Default:
Context: http, server, location

If the directive is set to a non-zero value, nginx will try tominimize the numberof send operations on outgoing connections to a FastCGI server by using eitherNOTE_LOWAT flag of thekqueue method,or the SO_SNDLOWAT socket option,with the specified size.

This directive is ignored on Linux, Solaris, and Windows.

Syntax: fastcgi_send_timeouttime;
Default:
Context: http, server, location

Sets a timeout for transmitting a request to the FastCGI server.The timeout is set only between two successive write operations,not for the transmission of the whole request.If the FastCGI server does not receive anything within this time,the connection is closed.

Syntax: fastcgi_socket_keepaliveonoff;
Default:
Context: http, server, location

This directive appeared in version 1.15.6.

Configures the “TCP keepalive” behaviorfor outgoing connections to a FastCGI server.By default, the operating system’s settings are in effect for the socket.If the directive is set to the value “on”, theSO_KEEPALIVE socket option is turned on for the socket.

Syntax: fastcgi_split_path_inforegex;
Default:
Context: location

Defines a regular expression that captures a value for the$fastcgi_path_info variable.The regular expression should have two captures: the first becomesa value of the $fastcgi_script_name variable, the secondbecomes a value of the $fastcgi_path_info variable.For example, with these settings

and the “/show.php/article/0001” request,the SCRIPT_FILENAME parameter will be equal to“/path/to/php/show.php”, and thePATH_INFO parameter will be equal to“/article/0001”.

Syntax: fastcgi_storeonoffstring;
Default:
Context: http, server, location

Enables saving of files to a disk.The on parameter saves files with pathscorresponding to the directivesalias orroot.The off parameter disables saving of files.In addition, the file name can be set explicitly using thestring with variables:

Fastcgi Protocol

The modification time of files is set according to the received“Last-Modified” response header field.The 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 storecan be put on different file systems.However, be aware that in this case a file is copiedacross two file systems instead of the cheap renaming operation.It is thus recommended that for any given location both saved files and adirectory holding temporary files, set by the fastcgi_temp_pathdirective, are put on the same file system.

This directive can be used to create local copies of static unchangeablefiles, e.g.:

Syntax: fastcgi_store_accessusers:permissions ..;
Default:
Context: http, server, location

Sets access permissions for newly created files and directories, e.g.:

If any group or all access permissionsare specified then user permissions may be omitted:

Syntax: fastcgi_temp_file_write_sizesize;
Default:
Context: http, server, location

Limits the size of data written to a temporary fileat a time, when buffering of responses from the FastCGI serverto temporary files is enabled.By default, size is limited by two buffers set by thefastcgi_buffer_size and fastcgi_buffers directives.The maximum size of a temporary file is set by thefastcgi_max_temp_file_size directive.

Syntax: fastcgi_temp_pathpath [level1 [level2 [level3]]];
Default:
Context: http, server, location

Defines a directory for storing temporary fileswith data received from FastCGI servers.Up to three-level subdirectory hierarchy can be used underneath the specifieddirectory.For example, in the following configuration

a temporary file might look like this:

See also the use_temp_path parameter of thefastcgi_cache_path directive.

Parameters Passed to a FastCGI Server

HTTP request header fields are passed to a FastCGI server as parameters.In applications and scripts running as FastCGI servers,these parameters are usually made available as environment variables.For example, the “User-Agent” header field is passed as theHTTP_USER_AGENT parameter.In addition to HTTP request header fields, it is possible to pass arbitraryparameters using the fastcgi_param directive.

Embedded Variables

Iis 10 Fastcgi

The ngx_http_fastcgi_module module supports embeddedvariables that can be used to set parameters using thefastcgi_param directive:

$fastcgi_script_name
request URI or, if a URI ends with a slash, request URI with an index filename configured by the fastcgi_index directive appended to it.This variable can be used to set theSCRIPT_FILENAME and PATH_TRANSLATEDparameters that determine the script name in PHP.For example, for the “/info/” request with thefollowing directivesthe SCRIPT_FILENAME

Fastcgi_read_timeout

parameter will be equal to“/home/www/scripts/php/info/index.php”.

When using the fastcgi_split_path_info directive,the $fastcgi_script_name variable equals the value ofthe first capture set by the directive.

Fastcgi_read_timeout Php

$fastcgi_path_info

Fastcgi_read_timeout Apache

the value of the second capture set by thefastcgi_split_path_info directive.This variable can be used to set thePATH_INFO parameter.