the cause of the problem
Because it takes a little time for nginx to start, and systemd reads the pid file before nginx finishes starting, which
causes the failure to read the pid
Solution
Let systemd wait for a while after executing the ExecStart command.
If your nginx takes longer to start, you can change the sleep time to a longer time.
Create a directory
mkdir -p /etc/systemd/system/nginx.service.d
Create a file override.conf in the new directory and enter the content
[Service]
ExecStartPost=/bin/sleep 0.1
然后
systemctl daemon-reload
systemctl restart nginx.service