Problem phenomenon:
1 Running the PHP script directly on the CLI returns normal data
2 Data returned through nginx access is truncated
Nginx error log: fastCgi_temp directory: fastCgi_temp directory: fastCgi_temp directory: fastCgi_temp directory:
2016/06/07 00:41:28 [crit] 32763#0: *5439 open() "/Data/apps/nginx/fastcgi_temp/5/02/0000000025" failed (13: Permission denied) while reading upstream, client: 203.171.237.2, server: www.36nu.com, request: "The GET/thread. HTTP / 1.0 HTML", upstream: "f astcgi: / / 127.0.0.1:9000",...Copy the code
The returned data is too large to be stored as a file, but nginx has no read and write permissions. Give fastCgi_temp read/write permission, problem solved.
chmod -R 764 /usr/local/nginx/fastcgi_temp/Copy the code
Nginx buffers a Response from the FastCGI Server into memory and then sends it to the client in turn. The buffer size is controlled by fastcgi_buffers and fastcgi_buffer_size values.
For example:
fastcgi_buffers 8 4K;
fastcgi_buffer_size 4K;
Fastcgi_buffers controls nginx to create up to eight buffers of 4K size, while fastcgi_buffer_size is the size of the first buffer when processing Response and is not included in the former. So the total maximum memory buffer size that can be created is 8*4K+4K = 36K. These buffers are dynamically generated based on the actual Response size and are not created at once. For example, for an 8K page, Nginx creates 2*4K buffers. When Response is less than or equal to 36K, of course all data is processed in memory. What if the Response is greater than 36K? This is where fastCgi_temp comes in. The extra data is temporarily written to a file and placed in this directory. 36Kb is cached in memory, and the rest is written to a file. The user running the Nginx Process does not have read/write permission to the fastcgi_temp directory.