pid
The `pid` directive specifies the file where NGINX should write its process ID when running in daemon mode.
Description
The pid directive is used in the NGINX core to define the location of a file that will contain the process ID (PID) of the master process when NGINX is started. This PID file is crucial for managing the NGINX process, allowing administrators to easily track and control it, especially when performing operations like graceful shutdown or reloading. By providing this directive with a file path, NGINX will create and write its PID to that file at startup. This aids in process management and ensures that system administrators can manage the service effectively without guessing the process's ID.
The parameter for the pid directive is a single argument specifying the file path where the PID will be stored. Typically, this path is set to a location that is writable by the user running the NGINX process, so ensuring proper permissions is important. In instances where the specified PID file cannot be created or written due to permission issues or wrong paths, NGINX will emit an error and exit without starting. Thus, it is essential to ensure that the path provided is valid and accessible. The pid directive must appear in the main configuration context, typically at the top level of the configuration file, before any server or location blocks, since it pertains to the NGINX process as a whole rather than individual server processes.
Config Example
pid /var/run/nginx.pid;
Ensure the specified PID file path is writable by the user running NGINX; otherwise, NGINX will fail to start.
Do not compile NGINX without the appropriate permissions for the specified PID path; this can lead to startup failures.
If changing the PID file location, make sure to stop NGINX before making this change, as it won't automatically update the PID file if the process is already running.