电脑疯子技术论坛|电脑极客社区

微信扫一扫 分享朋友圈

已有 1973 人浏览分享

虚拟机VM中的Linux启动Nginx时出现80端口被占用的问题解决方法

[复制链接]
1973 0
本帖最后由 zhaorong 于 2019-4-25 18:14 编辑

我用的虚拟机是VM,Linux版本是CentOS6.3在安装完Nginx之后准备启动Nginx服务
切到目录:
  1. [root@localhost ~]# cd /usr/local/nginx/sbin
  2. [root@localhost sbin]# ./nginx
复制代码

结果出现了问题:
  1. nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  2. nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  3. nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  4. nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  5. nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  6. nginx: [emerg] still could not bind()
复制代码

,Nginx服务使用80端口,看报错信息大概就是80端口已经被占用。
既然80端口已经被占用,那我们就来看看是什么占用了80端口。
  1. [root@localhost ~]# netstat -ntlp|grep 80
  2. tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      1468/nginx  
复制代码

看结果,是Nginx进程占用的。那我们就杀死Nginx进程再启动Nginx服务。
首先查看与Nginx有关的进程。据我观察,前四个是Nginx有关的进程,这四个进程要
全部杀死,才能启用Nginx。第四个进程是我们抓取Nginx的进程没有关系。
  1. [root@localhost sbin]# ps -ef |grep nginx
  2. www       2479     1  0 12:46         00:00:00 nginx: worker process                                          
  3. www       2480     1  0 12:46         00:00:00 nginx: worker process                                          
  4. www       2483     1  0 12:46         00:00:00 nginx: worker process                                          
  5. www       2485     1  0 12:46         00:00:00 nginx: worker process                                          
  6. root      2491  2405  0 12:47 pts/0    00:00:00 grep nginx
复制代码

然后我们执行命令:
  1. [root@localhost sbin]# kill -9 2479
  2. [root@localhost sbin]# kill -9 2480
  3. [root@localhost sbin]# kill -9 2483
  4. [root@localhost sbin]# kill -9 2485
复制代码

查看杀死Nginx1进程后的结果:
  1. [root@localhost sbin]# ps -ef |grep nginx
  2. root      2495  2405  0 12:48 pts/0    00:00:00 grep nginx
复制代码

这时候我们再次开启Nginx服务:
  1. [root@localhost sbin]# ./nginx
  2. [root@localhost sbin]#
复制代码

这时候成功了!!!!!!
这个过程中要注意的是:与Nginx有关的进程要全部杀死!我之前没有全部杀死导致一直有Nginx进程存在启用Nginx服务就一直报错。

您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

关注

0

粉丝

9021

主题
精彩推荐
热门资讯
网友晒图
图文推荐

Powered by Pcgho! X3.4

© 2008-2022 Pcgho Inc.