2-nginx常用命令

查看nginx配置文件路径 nginx -t

查看nginx进程 ps -ef | grep nginx

检测配置文件规则
nginx -c /etc/nginx/default.d/websocket.conf

改完配置后需要reload nginx -s reload

启动、停止、重载命令
systemctl start nginx.service
systemctl stop nginx.service
systemctl reload nginx.service
systemctl status nginx.service

nginx错误解决办法

1 重启电脑后,执行nginx -s reload时报错 nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or directory)
执行nginx -c /etc/nginx/nginx.conf搞定

[root@localhost nginx]# nginx -s reload
nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or directory)
[root@localhost nginx]# nginx -c /etc/nginx/nginx.conf
[root@localhost nginx]# nginx -s reload
[root@localhost nginx]# 

如果执行nginx -c /etc/nginx/nginx.conf还报错

[root@instance-ww74cmok-2 nginx]# nginx -c /etc/nginx/nginx.conf
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 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 [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 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 [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 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 [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 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 [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] still could not bind()

方法1:杀掉这个进程(慎重!!!,这个命令杀掉整个主机所有带有nginx的进程,包括docker容器启动的nginx镜像)
killall -9 nginx
systemctl start nginx.service

方法2:
-------------reload报错信息: nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or directory)
这个意思是在对应路径下找不到nginx的进程id,所以在/var/run目录下,新建一个nginx.pid文件,里面写上nginx的进程id即可(master process对应的那个id)


图片.png

代码

cd /var/run
touch nginx.pid
输入nginx的进程id(master process对应的那个id)
nginx -s reload

方法3:
找到所有的nginx进程,一个一个的杀掉,再重启nginx

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容