Aug 13 10:02:02 webserver systemd[1]: Stopped The NGINX HTTP and reverse proxy server.
Aug 13 10:02:02 webserver systemd[1]: Starting The NGINX HTTP and reverse proxy server...
Aug 13 10:02:02 webserver nginx[28250]: nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
Aug 13 10:02:02 webserver nginx[28250]: nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Aug 13 10:02:02 webserver systemd[1]: nginx.service: Failed to read PID from file /usr/local/nginx/logs/nginx.pid: Invalid argument
Aug 13 10:02:02 webserver systemd[1]: Started The NGINX HTTP and reverse proxy server.
這個錯誤訊息很令人在意, 雖然 Nginx 有正確服務
nginx.service: Failed to read PID from file /usr/local/nginx/logs/nginx.pid: Invalid argument
(nginx.pid 的路徑可能隨著你編譯安裝時的設定而不同)
在 Google 上搜尋了這項錯誤訊息的解決方法, 通常是在 nginx.service 檔裡加上啟動 Nginx 後的延遲, 例如:
ExecStartPost=/bin/sleep 0.1
原來是 Nginx 啟動尚未完成, systemd 就去讀取 nginx.pid, 於是造成錯誤訊息出現, 那麼來修改 nginx.service
nano /lib/systemd/system/nginx.service
將
ExecStartPost=/bin/sleep 0.1
貼入 nginx.service 的"[Service]"區塊內例如:
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecStartPost=/bin/sleep 0.1
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
編輯過 nginx.service 檔案需要重新載入
systemctl daemon-reload
嘗試重啟 Nginx
service nginx restart
可以看到 Nginx 不再吐錯誤訊息了
Aug 13 10:02:58 webserver systemd[1]: Starting The NGINX HTTP and reverse proxy server...
Aug 13 10:02:58 webserver nginx[28321]: nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
Aug 13 10:02:58 webserver nginx[28321]: nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Aug 13 10:02:59 webserver systemd[1]: Started The NGINX HTTP and reverse proxy server.