FastCGI module (FastCGI)

Source: Internet
Author: User
Document directory
  • · Instructions
  • Fastcgi_buffer_size
  • Fastcgi_buffers
  • Fastcgi_cache
  • Fastcgi_cache_key
  • Fastcgi_cache_path
  • Fastcgi_cache_methods
  • Fastcgi_cache_min_uses
  • Fastcgi_cache_use_stale
  • Fastcgi_cache_valid
  • Fastcgi_connect_timeout
  • Fastcgi_index
  • Fastcgi_hide_header
  • Fastcgi_ignore_client_abort
  • Fastcgi_ignore_headers
  • Fastcgi_intercept_errors
  • Fastcgi_max_temp_file_size
  • Fastcgi_no_cache
  • Fastcgi_next_upstream
  • Fastcgi_param
  • Fastcgi_pass
  • Fastcgi_pass_header
  • Fastcgi_read_timeout
  • Fastcgi_redirect_errors
  • Fastcgi_send_timeout
  • Fastcgi_split_path_info
  • Fastcgi_store
  • Fastcgi_store_access
  • Fastcgi_temp_path
  • · Parameters transmitted to the FastCGI Server
  • · Variables
  • $ Fastcgi_script_name
This module allows nginx to work with FastCGI and controls which parameters will be passed safely.
Example:
location / {
fastcgi_pass localhost:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
}
An instance in the cache:
http {
fastcgi_cache_path /path/to/cache levels=1:2 keys_zone=NAME:10m inactive=5m;
server {
location / {
fastcgi_pass http://127.0.0.1;

fastcgi_cache NAME;
fastcgi_cache_valid 200 302 1h;
fastcgi_cache_valid 301 1d;
fastcgi_cache_valid any 1m;
fastcgi_cache_min_uses 1;
fastcgi_cache_use_stale error timeout invalid_header http_500;
}
}
}
After 0.7.48, the cache follows the cache-control and expires of the backend server. After 0.7.66, the "cache-control:" private "and" no-store "headers are also followed. · Command fastcgi_buffer_size Syntax: fastcgi_buffer_size the_size;
Default Value: fastcgi_buffer_size 4 K/8 K;
Field used: HTTP, server, location
This parameter specifies how much buffer will be used to read the first part of the response from the FastCGI server.
Generally, this part contains a small response header.
The default buffer size is the size of each block in the fastcgi_buffers command. You can set this value to a smaller value. Fastcgi_buffers Syntax: fastcgi_buffers the_number is_size;
Default Value: fastcgi_buffers 8 4 K/8 K;
Field used: HTTP, server, location
This parameter specifies the number of local replies to be read from the FastCGI server and the number of large buffers. By default, this parameter is equal to the page size, which may be 4 kb depending on the environment, 8 K or 16 K. Fastcgi_cache Syntax: fastcgi_cache zone | off;
Default Value: Off
Field used: HTTP, server, location
Specify an area for the shared memory actually used by the cache. The same area can be used in different places. Fastcgi_cache_key Syntax: fastcgi_cache_key line
Default Value: None
Field used: HTTP, server, location
Set cache keywords, such:
fastcgi_cache_key localhost:9000$request_uri;
Fastcgi_cache_path Syntax: fastcgi_cache_path path [levels = m: N] keys_zone = Name: Size [inactive = time] [max_size = size]
Default Value: None
Field used: HTTP
The clean_time parameter has been removed in version 0.7.45.
This command specifies the FastCGI cache path and other parameters. All data is stored as files, and the cached key and file name are calculated as the MD5 value calculated by the proxy URL.
The level parameter sets the directory classification of the cache directory and the number of subdirectories. For example, if the command is set:
fastcgi_cache_path  /data/nginx/cache  levels=1:2   keys_zone=one:10m;
Data files are stored as follows:
/data/nginx/cache/c/29/b7f54b2df7773722d382f4809d65029c
Files in the cache are first written into a temporary file and subsequently moved to the last location of the cache directory. After version 0.8.9, temporary files and cached files can be stored in different file systems, however, you need to understand that this kind of movement is not a simple atomic rename system call, but a copy of the entire file, so it is best to use the same file system in the values of fastcgi_temp_path and fastcgi_cache_path.
In addition, all active keywords and data-related information are stored in the shared memory pool. The Value Name and size are specified by the key_zone parameter, and the inactive parameter specifies the data storage time in the memory, the default value is 10 minutes.
The max_size parameter sets the maximum cache value. A specified cache manager process periodically deletes old cache data. Fastcgi_cache_methods Syntax: fastcgi_cache_methods [get head post];
Default Value: fastcgi_cache_methods get head;
Field used: Main, HTTP, location
You cannot disable get/head, even if you just set it like this:
fastcgi_cache_methods  POST;
Fastcgi_cache_min_uses Syntax: fastcgi_cache_min_uses n
Default Value: fastcgi_cache_min_uses 1
Field used: HTTP, server, location
The command specifies how many requests the same URL will be cached. Fastcgi_cache_use_stale Syntax: fastcgi_cache_use_stale [updating | error | timeout | invalid_header | http_500]
Default Value: fastcgi_cache_use_stale off;
Field used: HTTP, server, location
In the case of gateway errors or timeout, nginx will transmit expired cache data. Fastcgi_cache_valid Syntax: fastcgi_cache_valid [http_error_code | time]
Default Value: None
Field used: HTTP, server, location
Specify the cache time for the specified HTTP return code, for example:
fastcgi_cache_valid  200 302  10m;fastcgi_cache_valid  404      1m;
Cache the response status codes 200 and 302 for 10 minutes, and 404 for 1 minute.
By default, the cache only processes 200,301,302 of the status.
You can also use any in the command to represent any one.
fastcgi_cache_valid  200 302 10m;fastcgi_cache_valid  301 1h;fastcgi_cache_valid  any 1m;
Fastcgi_connect_timeout Syntax: fastcgi_connect_timeout time
Default Value: fastcgi_connect_timeout 60
Field used: HTTP, server, location
Specify the connection timeout time of the same FastCGI server. The value cannot exceed 75 seconds. Fastcgi_index Syntax: fastcgi_index File
Default Value: None
Field used: HTTP, server, location
If the URI ends with a slash, the file name is appended to the URI, and the value is stored in the variable $ fastcgi_script_name. For example:
fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME  /home/www/scripts/php$fastcgi_script_name;
Request "/page. the script_filename parameter of PHP is set to "/home/www/scripts/PHP/page. PHP ", but"/"is"/home/www/scripts/PHP/index. PHP ". Fastcgi_hide_header Syntax: fastcgi_hide_header name
Field used: HTTP, server, location
By default, nginx does not transmit the "status" and "X-accel-..." headers from the FastCGI server to the client. This parameter can also hide some other headers.
If you must pass the "status" and "X-accel-..." headers, you must use fastcgi_pass_header to force them to be transmitted to the client. Fastcgi_ignore_client_abort Syntax: fastcgi_ignore_client_abort on | off
Default Value: fastcgi_ignore_client_abort off
Field used: HTTP, server, location
If the current connection request to the FastCGI server fails, you can use this command to prevent it from being disconnected from the nginx server. Fastcgi_ignore_headers Syntax: fastcgi_ignore_headers name [name...]
Field used: HTTP, server, location
This command prohibits the processing of some header fields of the FastCGI server response. For example, you can specify fields such as "X-accel-redirect", "x-accel-Expires ", "expires" or "cache-control. Fastcgi_intercept_errors Syntax: fastcgi_intercept_errors on | off
Default Value: fastcgi_intercept_errors off
Field used: HTTP, server, location
This command specifies whether to transmit 4xx and 5xx error messages to the client, or allows nginx to use error_page to process error messages.
You must explicitly specify the processing method in error_page to make this parameter valid, as Igor says, "If no proper processing method is available, nginx will not block an error, this error does not display its default page. You can use some methods to block the error. Fastcgi_max_temp_file_size Syntax: fastcgi_max_temp_file_size 0
Default Value :?
Field used :?
Disable the FastCGI Buffer Based on the source code. Fastcgi_no_cache Syntax: fastcgi_no_cache variable [...]
Default Value: None
Field used: HTTP, server, location
Determine under which circumstances the cached response will not be used, for example:
  fastcgi_no_cache $cookie_nocache  $arg_nocache$arg_comment;  fastcgi_no_cache $http_pragma     $http_authorization;
If it is a null string or equal to 0, the expression value is equal to false. For example, in the preceding example, if cookie "nocache" is set in the request, the cache will be bypassed. Fastcgi_next_upstream Syntax: fastcgi_next_upstream error | timeout | invalid_header | http_500 | http_503 | http_404 | off
Default Value: fastcgi_next_upstream error timeout
Field used: HTTP, server, location
The command specifies the situation in which the request will be forwarded to the next FastCGI Server:
· Error-An error occurred when connecting to the server for a transfer request or a request that is reading the response header.
· Timeout-the transfer request or the request that is reading the Response Header times out when connecting to the server.
· INVALID _ header-the server returns an empty or invalid response.
· HTTP _ 500-the server returns the 500 response code.
· HTTP _ 503-the server returns the 503 response code.
· HTTP _ 404-the server returns the 404 response code.
· Off-Prohibit requests from being sent to the next FastCGI server.
Note that empty data may have been transferred to the client before the transfer request is sent to the next server. Therefore, if an error or timeout occurs during data transmission, this command may not fix some transmission errors. Fastcgi_param Syntax: fastcgi_param parameter value
Default Value: None
Field used: HTTP, server, location
Specify parameters passed to the FastCGI server.
You can use strings, variables, or their combinations. The settings here do not inherit from other fields. The settings in the current field will clear any previous definitions.
Below are the minimum parameters required for a PHP:
  fastcgi_param  SCRIPT_FILENAME  /home/www/scripts/php$fastcgi_script_name;  fastcgi_param  QUERY_STRING     $query_string;
PHP uses the script_filename parameter to determine which script to execute. QUERY_STRING contains some parameters in the request.
To process a POST request, you need to add three other parameters:
  fastcgi_param  REQUEST_METHOD   $request_method;  fastcgi_param  CONTENT_TYPE     $content_type;  fastcgi_param  CONTENT_LENGTH   $content_length;
If PHP has -- enable-force-CGI-redirect during compilation, the redirect_status parameter with a value of 200 must be passed:
fastcgi_param  REDIRECT_STATUS  200;
Fastcgi_pass Syntax: fastcgi_pass FastCGI-Server
Default Value: None
Field used: HTTP, server, location
Specify the listening port and address of the FastCGI server, which can be local or other:
fastcgi_pass   localhost:9000;
Use UNIX socket:
fastcgi_pass   unix:/tmp/fastcgi.socket;
You can also use an upstream field name:
upstream backend  {  server   localhost:1234;} fastcgi_pass   backend;
Fastcgi_pass_header Syntax: fastcgi_pass_header name
Default Value: None
Use Field: HTTP, server, locationfastcgi_read_timeout Syntax: fastcgi_read_timeout time
Default Value: fastcgi_read_timeout 60
Field used: HTTP, server, location
The response timeout time of the front-end FastCGI server. If there are some FastCGI processes that have been output for a long time until they have finished running, or the front-end server response timeout error occurs in the error log, you may need to adjust this value. Fastcgi_redirect_errors Syntax: fastcgi_redirect_errors on | off
The command is renamed to fastcgi_intercept_errors. Fastcgi_send_timeout Syntax: fastcgi_send_timeout time default value: fastcgi_send_timeout 60 field used: HTTP, server, location
The command sets the time for the upstream server to wait for a FastCGI process to send data. If there are some FastCGI processes that have been output for a long time until they have finished running, you can modify this value, if you find some timeout errors in the error log on the server, you can add this value appropriately.
The timeout time of the Request server specified by the command indicates that the two handshakes are completed, instead of the full connection. If no data is transmitted by the client during this period, the server closes the connection. Fastcgi_split_path_info Syntax: fastcgi_split_path_info RegEx
Field used: Location
Available version: 0.7.31 or later. Example:
location ~ ^(.+\.php)(.*)$ {...fastcgi_split_path_info ^(.+\.php)(.*)$;fastcgi_param SCRIPT_FILENAME /path/to/php$fastcgi_script_name;fastcgi_param PATH_INFO $fastcgi_path_info;fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;...}
The script_filename parameter for the request "/show. php/article/0001" is set to "/path/to/PHP/show. php", and the path_info parameter is "/article/0001 ". Fastcgi_store Syntax: fastcgi_store [ON | off | path]
Default Value: fastcgi_store off
Field used: HTTP, server, location
The path for storing front-end files is specified. The parameter on specifies the path that will use the same root and alias commands. Off prohibits storage. In addition, variables can be used in the parameter to make the path clearer:
fastcgi_store   /data/www$original_uri;
The "last-modified" header in the response sets the last modification time of the file. To make these files more secure, you can save them as temporary files in a directory and use the fastcgi_temp_path command.
This command can be used to create a local copy for backend dynamic output that is not frequently changed. For example:
location /images/ {  root                 /data/www;  error_page           404 = /fetch$uri;} location /fetch {  internal;   fastcgi_pass           fastcgi://backend;  fastcgi_store          on;  fastcgi_store_access   user:rw  group:rw  all:r;  fastcgi_temp_path      /data/temp;   alias                  /data/www;}
Fastcgi_store is not a cache. In some cases, it is more like an image. Fastcgi_store_access Syntax: fastcgi_store_access users: permissions [users: permission...]
Default Value: fastcgi_store_access User: RW
Field used: HTTP, server, location
This parameter specifies the permission to create a file or directory, for example:
fastcgi_store_access  user:rw  group:rw  all:r;
If you want to specify the permissions of the person in a group, you can leave the user blank, for example:
fastcgi_store_access  group:rw  all:r;
Fastcgi_temp_path Syntax: fastcgi_temp_path path [level1 [level2 [level3]
Default Value: fastcgi_temp_path fastcgi_temp
Field used: HTTP, server, location
The command specifies the path of the temporary data file transmitted from another server. You can also specify the level-3 directory that has been hashed and the level value specifies the number of tags to be hashed. For example, in the following Configuration:
fastcgi_temp_path  /spool/nginx/fastcgi_temp 1 2;
Temporary files are similar to the following:
/spool/nginx/fastcgi_temp/7/45/00000123457
· Request headers for parameters sent to the FastCGI server are transmitted to the FastCGI server in the form of parameters and run on the FastCGI server using specific applications and scripts. These parameters are usually obtained in the form of environment variables, for example, the "User-Agent" header is transmitted with the http_user_agent parameter. In addition, some other HTTP headers can be freely transmitted using the fastcgi_param command. · Variable $ fastcgi_script_name: this variable is equal to a request URI ending with a slash plus the parameter specified by fastcgi_index. You can use this variable to replace script_filename and path_translated to determine the PHP script name.
For example, request "/INFO /":
 fastcgi_index  index.php;  fastcgi_param  SCRIPT_FILENAME  /home/www/scripts/php$fastcgi_script_name;
Script_filename is equal to "/home/www/scripts/PHP/INFO/index. php ".

From: http://www.cnblogs.com/shineshqw/articles/1828295.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.