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

2017-07-21T06:15:00

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

  1. sudo /etc/init.d/nginx start

结果提示错误:

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

我看了一下端口占用情况,并且尝试杀了进程:

  1. hankcs@ubuntu:~$ netstat -ntpl
  2. (并非所有进程都能被检测到,所有非本用户的进程信息将不会显示,如果想看到所有信息,则必须切换到 root 用户)
  3. 激活Internet连接 (仅服务器)
  4. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  5. tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN -
  6. tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN -
  7. hankcs@ubuntu:~$ killall -9 nginx
  8. nginx:没有发现操作

遇到这种问题我先用中文搜索了一下答案,发现大家都在装逼地说要杀nginx重复的进程。我试了下发现是扯淡,于是看了谷歌搜到的第一个英文页面,老外说是nginx先监听了ipv4的80端口之后又监听了ipv6的80端口,于是就重复占用了。更加坑人的是你去看了端口占用它又把80端口释放了,是不是很囧。

解决方案是编辑nginx的配置文件

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

修改这一段:

  1. listen 80;
  2. listen [::]:80 default_server;

  1. listen 80;
  2. listen [::]:80 ipv6only=on default_server;

然后启动nginx,完美解决!

 

via。http://www.hankcs.com/appos/linux/fix-nginx-bind-err.html

当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »
因本文不是用Markdown格式的编辑器书写的,转换的页面可能不符合MIP标准。