nginx reload 报错,彻底杀死nginx进程
1. nginx -s reload 报错
报错现象
[root@localhost ~]# nginx -s reload
nginx: [error] invalid PID number "" in "/run/nginx.pid"
解决方案
[root@localhost run]# nginx -c /etc/nginx/nginx.conf
[root@localhost run]#
执行该命令是 指定 nginx 的配置文件, 如上,执行完后没有报错 表示 nginx 正常运行了
2. nginx -c 报错
现象
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()
顺便看看 nginx -c 指令的作用, 如下可看
[root@localhost run]# nginx -h
nginx version: nginx/1.16.1
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /usr/share/nginx/)
-c filename : set configuration file (default: /etc/nginx/nginx.conf)
-g directives : set global directives out of configuration file
-c filename : set configuration file (default: /etc/nginx/nginx.conf)
用来设置配置文件 的
解决方案
杀死 nginx 程序即可重启nginx
- 通过
netstat
指令查询 出 80 端口的 占用程序
注意不要 直接 kill 3306 , 很多人这样干了, 杀不死
[root@localhost run]# netstat -ntlp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3036/nginx: master
tcp6 0 0 :::80 :::* LISTEN 3036/nginx: master
- 通过
ps
查出占用 程序的 端口号
[root@localhost run]# ps -ef | grep nginx
root 3036 1 0 15:01 ? 00:00:00 nginx: master process nginx -c /etc/nginx/nginx.conf
nginx 3037 3036 0 15:01 ? 00:00:00 nginx: worker process
nginx 3038 3036 0 15:01 ? 00:00:00 nginx: worker process
nginx 3039 3036 0 15:01 ? 00:00:00 nginx: worker process
nginx 3040 3036 0 15:01 ? 00:00:00 nginx: worker process
root 3074 2999 0 15:24 pts/0 00:00:00 grep --color=auto nginx
直接 grep nginx
程序 可以发现 占用端口 3036,3037,3038,3039,3040
, 全部 kill 掉即可
- kill 占用程序的 端口号
kill -9 3036
kill -9 ....