1. 程式人生 > 實用技巧 >Nginx pid檔案找不到 nginx: [error] open() "/run/nginx/nginx.pid" failed (2: No such file or directory)

Nginx pid檔案找不到 nginx: [error] open() "/run/nginx/nginx.pid" failed (2: No such file or directory)

Nginx pid檔案找不到

nginx: [error] open() "/run/nginx/nginx.pid" failed (2: No such file or directory)

原因:pid被誤刪除或者不存在

解決如下:停掉目前的nginx服務,重啟nginx,生成新的pid檔案

1. 檢視nginx服務所佔用的程序

/run/nginx # ps
PID   USER     TIME  COMMAND
    1 root      0:00 /bin/sh
   23 root      0:00 [nginx]
   28 root      0:00 [nginx]
  132 root      0
:00 nginx: master process nginx 190 nginx 0:00 nginx: worker process 206 root 0:00 sh 245 root 0:00 ps

2. 殺死程序

/run/nginx # kill 132
/run/nginx # ps
PID   USER     TIME  COMMAND
    1 root      0:00 /bin/sh
   23 root      0:00 [nginx]
   28 root      0:00 [nginx]
   29 root      0:00 sh
   35 root      0:00 [nginx]
   
36 root 0:00 sh 206 root 0:00 sh 246 root 0:00 ps

3. 重啟nginx

/run/nginx # nginx
/run/nginx # ls
nginx.pid # 該檔案已生成

  • 注意:檢視nginx的pid檔案生成存放目錄,如沒有設定則可設定,在nginx.conf配置檔案中設定,目錄不存在,則需要建立該目錄,否則重啟的時候pid生成不了。