1、重载配置

执行 nginx  -s   reload  命令,报错:找不到 nginx.pid 文件,无法打开。曾经屡试不爽的命令,此时,竟然失灵了? 刚开始,我一头雾水,有点丈二和尚摸不着头脑……

[root@127-0-0-1 nginx]# nginx -s reload
nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or directory)
[root@127-0-0-1 nginx]

问题一:为什么会报错?

答案: reload命令需要通过nginx.pid获取进程号,会去找/var/run.nginx.pid文件 ,如果不存在,就报错了。

2、进程文件

问题一:有关  pid(进程) 的配置在哪里?

[root@127-0-0-1 nginx]# vim nginx.conf

user  king;
worker_processes 4; error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

答案:在 nginx.conf 文件中的 pid 参数。显然nginx.pid 文件,就应该存在 /var/run/ 目录下。

问题二:nginx.pid 的生存周期?

答案: 一般情况,重启nginx,就会在/var/run/下生成一个nginx.pid文件。关闭nginx 或 kill  nignx的主进程后,nginx.pid就会消失……

[root@127-0-0-1 run]# cd /var/run
[root@127-0-0-1 run]# find -name nginx.pid
[root@127-0-0-1 run]#

 奇怪,还真没有 nginx.pid 文件。那么问题就来了,为什么nginx在启动的状态下,nginx.pid竟丢失了? 它去哪了? 还是谁掳走了它?

3、陷入深思

nginx.pid 去哪了?怎么丢失的?

1、误删  rm  -f  nginx.pid

2、恶作剧    被哪个同事给耍了,还是城市套路深,我要回农村……

4、解决方案

1)创建 nginx.pid 文件 —— 不是找不到文件么,我给你创建一个不得了嘛^_^

nginx.pid存放的是nginx的master进程号。

问题一: nginx 主进程号是多少?怎么查?

[root@127-0-0-1 run]# ps -ef|grep nginx
king 11183 12666 0 14:45 ? 00:00:00 nginx: worker process
king 11184 12666 0 14:45 ? 00:00:00 nginx: worker process
king 11185 12666 0 14:45 ? 00:00:00 nginx: worker process
king 11186 12666 0 14:45 ? 00:00:00 nginx: worker process
root 11315 11042 0 15:43 pts/0 00:00:00 grep --color=auto nginx
root 12666 1 0 Jun14 ? 00:00:00 nginx: master process nginx
[root@127-0-0-1 run]#

 答案:nginx 主进程(master process)号:12666

[root@127-0-0-1 run]# touch nginx.pid
[root@127-0-0-1 run]# echo "12666" > nginx.pid
[root@127-0-0-1 run]# cat nginx.pid
12666
[root@127-0-0-1 run]#

 执行命令:nignx  -s  relaod 不报错了,问题解决了,喜悦心情油然而生……

[root@127-0-0-1 nginx]# nginx -s reload
[root@127-0-0-1 nginx]#

 2)重启nginx —— 重启成功后,会生成一个nginx.pid文件。问题的克星——重启,是一把万能钥匙……

步骤一:杀掉进程

kill  -9  master 和 worker 进程号

步骤二:重启nginx

方法一:nginx

方法二:nginx  -c  指定目录的配置文件    例:nginx  -c  /etc/nginx/nginx.conf

步骤三:查看nginx.pid 文件

[root@127-0-0-1 nginx]# cd /var/run
[root@127-0-0-1 run]# find -name nginx.pid
./nginx.pid
[root@127-0-0-1 run]#

  步骤四:重载配置

执行命令:nginx -s  reload ,不报错,问题解决了……

5、一顿瞎操作

想法一:进程文件写入一个不存在的进程号,重载配置会怎么样?

[root@127-0-0-1 run]# echo "8888"> nginx.pid
[root@127-0-0-1 run]# cat nginx.pid
8888
[root@127-0-0-1 run]# nginx -s reload
nginx: [alert] kill(8888, 1) failed (3: No such process)
[root@127-0-0-1 run]#

想法二:不杀进程,直接重启 nginx 会报错么?

[root@127-0-0-1 run]# nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[root@127-0-0-1 run]#

报错:80端口,被占用。不是别人,是自己(nginx)……

想法三:写错配置,会有什么影响?

[root@127-0-0-1 conf.d]# cat app.conf
server {
listen 80; king #wrong location
server_name 0.0.0.0:80;

首先测试配置,然后重载

[root@127-0-0-1 conf.d]# nginx -t
nginx: [emerg] unknown directive "king" in /etc/nginx/conf.d/HKIN-CRS.conf:3
nginx: configuration file /etc/nginx/nginx.conf test failed
[root@127-0-0-1 conf.d]# nginx -s reload
nginx: [emerg] unknown directive "king" in /etc/nginx/conf.d/HKIN-CRS.conf:3
[root@127-0-0-1 conf.d]#

  

谁掳走了 nginx.pid 文件?的更多相关文章

  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 dir ...

  2. nginx 启动报错找不到nginx.pid文件

    这个问题的出现应该是系统找不到nginx的配置文件nginx.conf,所以,我们要告诉系统配置文件的位置:' --- 使用nginx -c /usr/local/nginx/conf/nginx.c ...

  3. nginx重启报找不到nginx.pid的解决方法

    nginx被停止(nginx -s stop)或者直接杀掉了进程(kill -9 nginx的进程号)后,调用命令(nginx -s reload 或者 nginx -s reopen)会报错:无法找 ...

  4. 关于nginx.pid丢失的解决办法

    在停掉nginx的过程中突然出现如下的提示:

  5. 解决Nginx: [error] open() "/usr/local/Nginx/logs/Nginx.pid

    重新启动服务器,访问web服务发现无法浏览啦!登陆服务器之后进到nginx使用./nginx -s reload重新读取配置文件,发现报nginx: [error] open() "/usr ...

  6. linux之pid文件

    在命令行中经常看到*.pid文件 其实这些文件是在启动进程的时候系统给这个进程的master进程分配的进程号 比如/usr/local/nginx/logs/nginx.pid文件 打开这个文件会发现 ...

  7. 解决nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed错误

    重新启动服务器,访问web服务发现无法浏览,登陆服务器之 后进到nginx使用./nginx -s reload重新读取配置文件,发现报nginx: [error] open() "/usr ...

  8. 解决linux重启后无法开启nginx问题“var/run/nginx/nginx.pid" no such file or directory问题

    起因:每次重启虚拟机后,var/run/nginx/目录都会被删除,所以无法在这个目录创建nginx.pid文件, 可以自己创建var/run/nginx/目录,然后可以运行,但治标不治本,下次虚拟机 ...

  9. 重启nginx后丢失nginx.pid的解决方法

    一,nginx的停止操作 停止操作是通过向nginx进程发送信号来实现的. 步骤1:查询nginx主进程号 复制代码 代码如下: ps -ef | grep nginx 在进程列表里 面找master ...

随机推荐

  1. 【VS开发】【图像处理】相机中白平衡的算法模拟实现

    相机主要技术点为3A算法. 而3A算法主要指的是自动对焦(AF).自动曝光(AE)及自动白平衡(AWB).自动白平衡:根据光源条件调整图片颜色的保真程度. 网上时常有类似招聘如下的招聘信息: ---- ...

  2. Mybatis--<![CDATA[ sql 语句 ]]>

    在mapper文件中写sql语句时,遇到特殊字符时,如:< 等,建议使用<![CDATA[ sql 语句 ]]>标记,将sql语句包裹住,不被解析器解析   在使用mybatis 时 ...

  3. 浅谈spring配置定时任务的几种方式

    网上看到好多关于定时任务的讲解,以前只简单使用过注解方式,今天项目中看到基于配置的方式实现定时任务,自己做个总结,作为备忘录吧. 基于注解方式的定时任务 首先spring-mvc.xml的配置文件中添 ...

  4. 【转】mysql用sql实现split函数

    关键词:mysql split mysql根据逗号将一行数据拆分成多行数据1.原始数据演示 2.处理结果演示 3.sql语句 SELECT a.id , a.NAME , substring_inde ...

  5. 百度之星 2019 预赛三 A 最短路 1

    题目链接 分析 异或运算满足「三角不等式」. $\forall a, b, c \in \mathbb{Z}_{\ge 0}$,有 $a \xor b \le (a \xor c) + (c \xor ...

  6. Tarjan水题系列(5):最大半连通子图 [ZJOI2007 luogu P2272]

    题目 大意: 缩点后转为求最长链的长度和最长链的个数 思路: 看懂题就会做系列 长度和个数都可以拓扑排序后DP求得 毕竟是2007年的题 代码: 如下 #include <cstdio> ...

  7. empty() 为true

    //empty() 为truevar_dump(empty(0));var_dump(empty('0'));var_dump(empty(array()));var_dump(empty(null) ...

  8. 實現QQ第三方登錄

    <?php // 写几个函数,分别用于获取code,token,openid,用户信息 // 跳转到QQ授权登录页面 function code(){ $response_type='code' ...

  9. PythonDay13

    第十三章 今日内容 匿名函数 内置函数二 闭包 匿名函数 匿名函数就是一行函数,关键字是lambda lambda x:x# lambda 参数:返回值x 是普通函数的形参 可以不定义形参:x 是 普 ...

  10. RabbitMQ入门教程(十七):消息队列的应用场景和常见的消息队列之间的比较

    原文:RabbitMQ入门教程(十七):消息队列的应用场景和常见的消息队列之间的比较 分享一个朋友的人工智能教程.比较通俗易懂,风趣幽默,感兴趣的朋友可以去看看. 这是网上的一篇教程写的很好,不知原作 ...