cgi_body_only
The 'cgi_body_only' directive determines whether only the body of a CGI response is sent to the client, omitting the headers.
Description
The 'cgi_body_only' directive in the NGINX CGI module is used to control the response behavior when processing CGI scripts. When enabled, this directive instructs NGINX to send only the body of the response from the CGI script, excluding any headers that would typically accompany an HTTP response. This can be useful in scenarios where the headers are either not needed or should be omitted for functionality or performance reasons, allowing the client to only receive the necessary content directly.
In terms of implementation, 'cgi_body_only' acts as a flag; when set to 'on', it informs NGINX to suppress the standard response headers. This setting can be configured per server or location block, thus providing flexibility in how specific parts of your server's configuration handle CGI responses. This capability allows developers to tailor the behavior of CGI scripts based on their unique requirements, particularly in applications where the overhead of packing headers is undesirable.
The directive has become a useful option for developers keen on optimizing their applications, as it can reduce the size of the response payload sent over the network by removing unnecessary headers. While this might enhance performance for specific use cases, care should be taken to ensure that omitting headers does not impact client interoperability or expectations, especially regarding content type and caching directives.
Config Example
location /cgi-bin/ {
cgi_pass unix:/var/run/fcgi.sock;
cgi_body_only on;
}If 'cgi_body_only' is set to 'on', clients may not receive important headers like Content-Type or caching directives, which could affect how responses are processed especially in browsers.
Ensure that your CGI scripts correctly handle responses without relying on headers, as their absence might lead to unexpected client behavior.