ubuntu – 无法重启nginx,bind()失败(98:地址已在使用中)

前端之家收集整理的这篇文章主要介绍了ubuntu – 无法重启nginx,bind()失败(98:地址已在使用中)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我知道这个主题以各种不同的形式存在,但我无法解决我的问题.如果我运行服务Nginx restart,Nginx将失败并显示以下日志:

2015/03/14 08:36:42 [emerg] 9400#0: bind() to 0.0.0.0:80 Failed (98: Address already in use)
2015/03/14 08:36:42 [emerg] 9400#0: bind() to 0.0.0.0:80 Failed (98: Address already in use)
2015/03/14 08:36:42 [emerg] 9400#0: bind() to 0.0.0.0:80 Failed (98: Address already in use)
2015/03/14 08:36:42 [emerg] 9400#0: bind() to 0.0.0.0:80 Failed (98: Address already in use)
2015/03/14 08:36:42 [emerg] 9400#0: bind() to 0.0.0.0:80 Failed (98: Address already in use)
2015/03/14 08:36:42 [emerg] 9400#0: still could not bind()

我在启用站点时只有一个配置加载.当我跑:

$grep -slir "listen 80"
$sites-available/default

显示默认配置有listen 80,但这并不重要,因为它不在启用站点的情况下.

$ps ax -o pid,ppid,%cpu,vsz,wchan,command|egrep '(Nginx|PID)'
  PID  PPID %cpu    VSZ WCHAN  COMMAND
 9468     1  0.0  97188 sigsus Nginx: master process /usr/sbin/Nginx
 9471  9468  0.0  97328 ep_pol Nginx: worker process
 9472  9468  0.0  97368 ep_pol Nginx: worker process
 9693  9641  0.0   9448 pipe_w egrep --color=auto (Nginx|PID)

这是一个netstat,显示正在使用的端口:

$netstat -tulpn

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      1300/master
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      9468/Nginx
tcp        0      0 0.0.0.0:2812            0.0.0.0:*               LISTEN      5980/monit
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      1174/MysqLd
tcp        0      0 127.0.0.1:11211         0.0.0.0:*               LISTEN      1155/memcached
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      9468/Nginx
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1113/sshd
tcp6       0      0 :::25                   :::*                    LISTEN      1300/master
tcp6       0      0 :::9000                 :::*                    LISTEN      9106/hhvm
tcp6       0      0 :::22                   :::*                    LISTEN      1113/sshd
udp        0      0 127.0.0.1:11211         0.0.0.0:*                           1155/memcached

这是我在启用网站的完整配置(在那里唯一的配置):

server {
    listen                  443 ssl default_server;

    limit_conn              gulag 15;
    server_name             www.my-website.com;

    access_log              /home/my-website/logs/access.log;
    error_log               /home/my-website/logs/error.log info;

    root                    /home/my-website/web;
    index                   index.PHP index.html;

    ssl_certificate /etc/Nginx/ssl/my-website.com.chained.crt;
    ssl_certificate_key /etc/Nginx/ssl/my-website.com.key;
    ssl_prefer_server_ciphers On;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;

    include                 /etc/Nginx/includes/my-website_redirects_https.inc;
    include                 /etc/Nginx/includes/file_cache.inc;
    include                 /etc/Nginx/includes/wordpress.inc;
}

server {
    listen                  80;
    server_name             my-website.com www.my-website.com;
    return                  301 https://$server_name$request_uri;
}

server {
    listen                  443;
    server_name             my-website.com;
    return                  301 https://www.$server_name$request_uri;
}

server {
    server_name
        some-other-website1.com         www.some-other-website1.com
        some-other-website2.com         www.some-other-website2.com
        some-other-website3.com         www.some-other-website3.com
        some-other-website4.com         www.some-other-website4.com
        some-other-website5.com         www.some-other-website5.com

    rewrite ^(.*)$https://www.my-website.com/some/page/ permanent;
}

server {
    server_name
        some-other-website6.com         www.some-other-website6.com
        some-other-website7.com         www.some-other-website7.com
        some-other-website8.com         www.some-other-website8.com

    rewrite ^(.*)$https://www.my-website.com/some/other/page/ permanent;
}

server {
    server_name     subdomain.my-website.com;

    rewrite ^(.*)$https://some.otherwebsite.com/ permanent;
}

server {
    server_name
        some-other-website9.com         www.some-other-website9.com
        some-other-website10.com         www.some-other-website10.com
        some-other-website11.com         www.some-other-website11.com

    rewrite ^(.*)$ https://www.my-website.com/ permanent;
}

我想知道是否因为我的配置发生了这个bind()错误.我有什么想法可能做错了吗?我正在使用Nginx / 1.4.6(Ubuntu).任何帮助将不胜感激.@H_502_42@

最佳答案@H_502_42@
尝试停止Nginx

service Nginx stop

检查Nginx是否仍在运行:

ps ax | grep Nginx

如果仍在运行,请终止进程:

kill -p PID

检查Nginx状态,不会运行:

ps ax | grep Nginx

然后做一个干净的开始:

service Nginx start

在同样的问题之后,这对我有用.@H_502_42@ 原文链接:https://www.f2er.com/nginx/435663.html

猜你在找的Nginx相关文章