Here’s a tip on how to fix the error message:
nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument
quick and easy. This workaround should do it for you.
This behavior is a known bug, caused by a race condition between nginx and systemd. Systemd is expecting the PID file to be populated before nginx had the time to create it. To fix the error, you have to create the file.
Step 1. Create the directory /etc/systemd/system/nginx.service.d
Create a directory named nginx.service.d in /etc/systemd/system/:
Step 2. Print data to file
printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" > /etc/systemd/system/nginx.service.d/override.conf
Make sure that you enter the string after the > on its very own line so that printf writes its output into the configuration file /etc/systemd/
Step 3. Reload the daemon
Reload systemd manager configuration:
This will rerun all generators, reload all unit files and recreate the entire systemd dependency tree.
Step 4. Restart NGINX
This line will restart NGINX for you:
systemctl restart nginx
The error should be fixed now.
An alternative workaround
Another workaround is removing the PIDFile option and adding the line:
/bin/rm -f /run/nginx.pid
You can find the full documentation of this bug at: