working_directory
Sets the working directory for the NGINX worker processes.
Description
The working_directory directive in NGINX is used to specify the directory in which the worker processes will operate. This setting is crucial as it determines the default working directory for processes that do not have a specific directory set when they are executed. By specifying a working directory, you can ensure that relative paths used in configurations or other directives are resolved correctly relative to that directory.
This directive takes a single argument, which should be the path to the directory you wish to set as the working environment for NGINX worker processes. It must be used in the main context of the NGINX configuration file. When NGINX worker processes are started, they inherit this setting and use it to resolve relative paths, handle file operations, and manage logging among other tasks, which can help in managing permissions and organizing file storage effectively.
It is important to ensure that the specified directory is accessible to the NGINX process and that it has the appropriate permissions set. Failure to provide an accessible directory may result in errors during the operation of NGINX, particularly in the handling of files such as logs or configuration files that rely on the working directory for their paths.
Config Example
working_directory /var/www/html;
Ensure that the specified directory exists before starting NGINX as missing directories can lead to startup errors.
The user running NGINX must have the necessary permissions to access the specified working directory.
Using relative paths can lead to confusion; it's often better to use absolute paths.