The conventional configuration described Nginx FastCGI

Original link: http: //blog.51cto.com/blief/1739655

definition

CGI: full name "Common Gateway Interface", Http server as a tool to "talk" with the program on other machines, the program typically runs on a network server. 

FastCGI full name: "Fast Common Gateway Interface", he can always perform with, in addition to support distributed computing, that FastCGI web server program can 

execute and accepts requests from other sites on the host server other than the 

FastCGI is a language-independent, CGI may extend open scalable architecture, the main behavior is to keep the CGI process the interpreter and therefore achieve higher performance in memory. 

As we all know, CGI interpreter repeated loading is the main reason for poor performance CGI, CGI interpreter if kept in memory and accept scheduling FastCGI process manager, can provide good performance, scalability, Fail- Over characteristics, etc.

FastCGI is telescopically a high speed interface for communicating between the HTTP server and dynamic scripting language. The most popular HTTP server support FastCGI, including Apache, Nginx and lighttpd and so on. At the same time, FastCGI also many scripting languages, among them PHP. 

FastCGI is the development of improvements comes from CGI. The main drawback of traditional CGI interface mode is poor performance, as you will need to restart the script every time the parser encounters HTTP server program to perform dynamic resolution, then returns the results to the HTTP server. It is almost not available when dealing with high concurrent access. 

In addition traditional CGI interface mode security is also poor, is now rarely used. FastCGI interface mode using C / S structure, and can be distinguished from the HTTP server script analyzing server, start script analyzing the one or more script analyzing daemon on the server. When the HTTP server every time they meet a dynamic program that can be delivered directly to the FastCGI process is performed,

then the result will be returned to the browser. This way you can make an HTTP server requests exclusively dealing with static or dynamic result script server back to the client, which improves the performance of the entire application system to a large extent.

principle

1, WebServer Start is loaded FastCGI process manager 
2, FastCGI process manager initializes itself, a plurality of CGI to start the interpreter and waits for a connection from the process of Web Server 
3, when a client request arrives Web Server, FastCGI process manager selects and is connected to a CGI interpreter, Web Server

 

The conventional configuration described NGINX FastCGI

1, fastcgi_connect_timeout 

configuration syntax: fastcgi_connect_timeout time (s) 

Default: FastCGI_connect_timeout 60s 

configuration area: http server location 

Configuration Description: Specifies NGINX rear end FastCGI server connection time

 

2, fastcgi_send_timeout 
configuration syntax: fastcgi_send_timeout time (s) 

Default: fastcgi_send_timeout 60s; 

configuration area: http server location 

Parameter Description: Specifies nginx request time to transfer the rear end (refer to two-way handshake has completed the transfer request to the fastcgi overtime time)

 

3, fastcgi_read_timeout 

configuration syntax: fastcgi_read_timeout time (s) 

Default: fastcgi_send_timeout 60s; 

configuration area: http server location 

Parameter Description: Specifies nginx fastcgi rear receiving the response request timeout (refer to two-way handshake has been completed after receiving nginx fastcgi response request time)

  

4, fastcgi_buffer_size 

configuration syntax: fastcgi_buffer_size size (in units of k, is generally an integral multiple of 4) 

Default: fastcgi_buffer_size 4k | 8K 

configuration area: http server location 

Parameter Description: Specifies the first portion in response nginx fastcgi read how much the required buffer region, this value indicates the buffer to be used in response to a first portion of a 64kb response 
(response header) can be set to the size of the buffer fastcgi_buffers

  

5, fastcgi_buffers 

configuration syntax: fastcgi_buffers num size (in units of k, is generally an integral multiple of 4) 

Default: fastcgi_buffers 8 4k | 8K 

configuration area: http server location 

Parameter Description: refers to how much the required buffer nginx fastcgi of buffer acknowledgment request (full response), if the page size of a php script is generated 256kb, then four 64kb buffers assigned to cache, if the page is larger than 256kb, 

that is greater than the portion of cached to 256kb fastcgi_temp specified path, but because the in-memory data processing is much faster than disk, so this value should be an intermediate value of the page size of the site in php generated, 

the page If the site most php script is generated: 256kb, you can set to "8 16k 4 64k "

 

6, fastcgi_busy_buffers_size 

configuration syntax: fastcgi_busy_buffers_size size (in units of K, usually 2 times fastcgi_buffers value) 

Default value: fastcgi_busy_buffers 8k | 16K 

configuration area: http server location 

Item Description: The entire data requests require much cache, it is recommended to twice the value of fastcgi_buffers

  

7, fastcgi_temp_file_write_size 

configuration syntax: fastcgi_temp_file_write_size size (in units of K, usually twice fastcgi_buffers value) 

Default value: fastcgi_temp_file_write_size 8k | 16K 

configuration area: http server location 

Item Description: Write cache files using much of the data blocks, the default value value is 2 times fastcgi_buffer

  

8, fastcgi_temp_path 

configuration syntax: fastcgi_temp_path path (temporary file storage path) 

configuration area: http server location 

Item Description: fastcgi temporary file storage path 

Note: This configuration items, but often not used

  

9, fastcgi_cache_path 

configuration syntax: fastcgi_cache_path path [Levels = Levels] [use_temp_path = ON | OFF] keys_zone = name: size [inactive = Time] [MAX_SIZE = size] [loader_files = Number The] [loader_sleep = Time] 

[loader_threshold = Time] [purger = on | off] [ purger_files = number] [purger_sleep = time] [purger_threshold = time]; configuration area: http server location Description CI: path definition fastcgi cache and other settings

  

10, fastcgi_cache 

configuration syntax: fastcgi_cache zone | OFF (wherein fastcgi_cache_path zone corresponding to the zone name) 

Default: OFF fastcgi_cache 

configuration area: http, server, location 

Parameter Description: fastcgi_cache open and define a name, an error can be prevented nginx 502 reduce cpu load, but can also cause other problems, be selected according to the needs of

  

11, fastcgi_cache_valid 

configuration syntax: fastcgi_cache_valid {code} time 

configuration area: http server location 

Parameter Description: Specifies the cache time for the specified response code 

fastcgi_cache_valid 200 302 1h; fastcgi_cache_valid any 1m ; 

The above means that for the status code 200 302 Web cache 1 hour, 1 minute other page caching

  

12, fastcgi_cache_key 

configuration syntax: fastcgi_cache_key value 

configuration area: http server location 

Item Description: The value of a key, Nginx will take the key of md5 as cache files if you set the cache hash table of contents, Nginx will be taken forward from the back the corresponding number of bits as the directory 

for example: fastcgi_cache_key "$ request_method: // $ host $ request_uri";

  

13, fastcgi_cache_min_uses 

configuration syntax: fastcgi_cache_min_uses 

configuration area: http server location 

Item Description: URL requests through at least how many times will be cached

  

Guess you like

Origin www.cnblogs.com/liaopeng123/p/11422794.html