cgi_working_dir
Sets the working directory for CGI scripts executed by NGINX.
Description
The cgi_working_dir directive allows the user to specify the working directory for CGI scripts when they are executed by NGINX. This directive can be particularly useful when scripts need to operate in a specific directory context, such as accessing relative file paths or creating files. It affects how the environment is prepared for the CGI script, as it determines where the script will run from. The working directory provided in this directive becomes the current working directory for the CGI process spawned by NGINX.
This directive can be placed in both the server and location contexts, allowing for flexibility depending on the scope required. The argument for this directive is a string that represents the directory path. If multiple cgi_working_dir directives are specified, the most specific (normally the one in the closest context) is used, unless overridden directly in the CGI configuration. Errors may occur if the specified directory does not exist or if the NGINX worker process does not have sufficient permissions to access it.
Config Example
server {
location /cgi-bin {
cgi_pass unix:/tmp/cgi.sock;
cgi_working_dir /var/www/cgi-scripts;
}
}Ensure the specified directory exists, as a nonexistent directory can lead to CGI execution failures.
Check that the NGINX worker process has the necessary permissions to read and execute scripts in the specified working directory.