一聚教程网:一个值得你收藏的教程网站

热门教程

nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)错误解决方法

时间:2022-06-30 18:41:21 编辑:袖梨 来源:一聚教程网

今天在ubuntu10.04上面安装nginx,安装完成之后尝试启动nginx,使用命令:

 代码如下 复制代码

sudo /etc/init.d/nginx start

结果发现启动不了,出现如下错误提示

hankcs@ubuntu:~$ sudo /etc/init.d/nginx start
[sudo] password for hankcs:
 * Starting nginx nginx                                                         nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

问题描述:地址已被使用。可能nginx服务卡死了,导致端口占用,出现此错误。


解决方法:

首先用lsof:80看下80端口被什么程序占用。lsof返回结果如下:

 代码如下 复制代码


hankcs@ubuntu:~$ netstat -ntpl

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      -              
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -              
hankcs@ubuntu:~$ killall -9 nginx

nginx:没有发现操作

nginx的配置文件

 代码如下 复制代码

hankcs@ubuntu:~$ sudo gedit /etc/nginx/sites-available/default

修改这一段:

listen 80;
listen [::]:80 default_server;

listen 80;
listen [::]:80 ipv6only=on default_server;

然后启动nginx,完美解决!

如果你发现操作我们可以如下操作

发现是nginx程序,所以我们把nginx服务k掉,重新启动服务。。命令如下:

 代码如下 复制代码

kill -9 3274
kill -9 3547

service nginx start
Starting nginx:       

 补充一个80占用解决办法

原因: 端口 80 端口被占用,用 “lsof -i:80" 命令查看一下是什么程序占用了80端口,我的结果显示是 80 端口被 apache 占用
[root@localhost html]# lsof -i:80
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
httpd   1203   root    4u  IPv6   8514      0t0  TCP *:http (LISTEN)
httpd   1217 apache    4u  IPv6   8514      0t0  TCP *:http (LISTEN)
httpd   1218 apache    4u  IPv6   8514      0t0  TCP *:http (LISTEN)
httpd   1219 apache    4u  IPv6   8514      0t0  TCP *:http (LISTEN)
httpd   1220 apache    4u  IPv6   8514      0t0  TCP *:http (LISTEN)
httpd   1221 apache    4u  IPv6   8514      0t0  TCP *:http (LISTEN)
httpd   1222 apache    4u  IPv6   8514      0t0  TCP *:http (LISTEN)
httpd   1223 apache    4u  IPv6   8514      0t0  TCP *:http (LISTEN)
httpd   1224 apache    4u  IPv6   8514      0t0  TCP *:http (LISTEN)
httpd   1285 apache    4u  IPv6   8514      0t0  TCP *:http (LISTEN)
httpd   1830 apache    4u  IPv6   8514      0t0  TCP *:http (LISTEN)
httpd   1871 apache    4u  IPv6   8514      0t0  TCP *:http (LISTEN)
httpd   1872 apache    4u  IPv6   8514      0t0  TCP *:http (LISTEN)
httpd   1873 apache    4u  IPv6   8514      0t0  TCP *:http (LISTEN)
httpd   1874 apache    4u  IPv6   8514      0t0  TCP *:http (LISTEN)
httpd   1875 apache    4u  IPv6   8514      0t0  TCP *:http (LISTEN)
httpd   1876 apache    4u  IPv6   8514      0t0  TCP *:http (LISTEN)
httpd   1877 apache    4u  IPv6   8514      0t0  TCP *:http (LISTEN) 解决办法: 依照自己情况适当处理,我的是把 apache 停掉了并直接卸载了(因为 apache 我已经不用了),重新启动了 nginx

 

热门栏目