> How to fix the NGINX error “Failed to read PID from file”, quick and easy
以下是有關如何修復錯誤消息的提示:
```
nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument
或者
openresty.service: Failed to parse PID from file /run/openresty.pid: Invalid argument
```
此行為是一個已知錯誤,由nginx和systemd之間的競爭條件引起。 Systemd期望在nginx有時間創建之前填充PID文件。要修復錯誤,您必須創建該文件。
**Step 1. 創建目錄:**`/etc/systemd/system/nginx.service.d`
Create a directory named nginx.service.d in /etc/systemd/system/:
```
mkdir /etc/systemd/system/nginx.service.d
```
**Step 2. Print data to file**
```
printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" > /etc/systemd/system/nginx.service.d/override.conf
```
確保在其自己的行上輸入>之后的字符串,以便printf將其輸出寫入配置文件:
```
/etc/systemd/system/nginx.service.d/override.conf
```
**Step 3. Reload the daemon**
Reload systemd manager configuration:
```
systemctl daemon-reload
```
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:
```
ExecStopPost=/bin/rm -f /run/nginx.pid
```
https://www.cloudinsidr.com/content/heres-fix-nginx-error-failed-read-pid-file-linux/
- 序言
- Nginx從入門到實踐
- 第一章 前言
- 第二章 基礎篇
- 2-1 什么是Nginx?
- 2-2 常見的中間件服務
- 2-3 Nginx特性-多路復用
- 2-4 Nginx特性-輕量級
- 2-5 Nginx特性-Cpu親和
- 2-6 Nginx特性_實現優點4
- 2-7 Nginx的快速安裝
- 2-8 Nginx安裝目錄
- 2-9 Nginx編譯配置參數
- 2-10 Nginx默認配置語法
- 2-11 Nginx默認站點啟動
- 2-12 HTTP請求
- 2-13 Nginx日志
- 2-14 Nginx模塊介紹
- 2-15 Nginx的請求限制
- 2-16 Nginx的訪問控制
- 第三章 場景實踐篇
- 3-1 Nginx作為靜態資源web服務
- 1、靜態資源類型
- 2、CDN場景
- 3、配置語法
- 4、場景演示
- 5、瀏覽器緩存原理
- 6、跨站訪問
- 7、防盜鏈
- 3-2 Nginx作為代理服務
- 1、代理服務.
- 2、反向代理配置場景
- 3、正向代理配置場景
- 4、代理配置和規范
- 3-3 Nginx作為負載均衡服務
- 1、配置語法與場景
- 2、參數講解
- 3、backup狀態演示
- 4、輪詢策略
- 3-4 Nginx作為緩存服務
- 1、緩存服務配置語法
- 2、場景配置演示.
- 3、分片請求
- 第四章 深度學習篇
- 4-1 Nginx動靜分離
- 4-2 Rewrite規則
- 1、配置語法
- 2、正則表達式
- 3、規則中的flag
- 4、redirect和permanent區別
- 5、規則場景
- 4-3 Nginx進階高級模塊
- 1、secure_link模塊作用原理
- 2、Geoip讀取地域信息模塊
- 4-4 基于Nginx的HTTPS服務
- 1、原理和作用
- 2、證書簽名生成CA證書.
- 3、實戰場景配置蘋果要求的openssl
- 4、HTTPS服務優化
- 4-5 Nginx與Lua的開發
- 1、Nginx與Lua特性與優勢
- 2、Lua基礎開發語法
- 3、Lua的指令及api接口
- 4、實戰場景灰度發布
- 第五章 Nginx架構篇
- 安全
- 5-27 Nginx+LUA防火墻功能
- Nginx 錯誤專題
- 1、 Failed to parse PID from file
- 2、error: the HTTP gzip module requires the zlib library
- 3、open() “/usr/local/nginx/html/favicon.ico” failed (2: No such file or directory)
- Openresty
- 控制命令