nginx不会停止/重启失败(98:地址已在使用中)

时间:2015-05-14 15:13:24

标签: nginx ubuntu-14.04

版本: 这是一个Ubuntu 14.04的新鲜出现 NGINX 1.4.6

要点: 发出服务nginx停止,不停止服务器,发出nginx重启提供失败!错误已经在使用中。

详细说明: 我相信这是我的vhosts的一个问题,如果我在nginx.conf中注释了包含for sites-enabled,它们都表现正常。我已经阅读了多个网站,说明了ipv6only和ipv4,但这似乎很好,因为这是开箱即用的默认

未安装Apache,nginx是唯一的服务器。

调试:

nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

lsof -i :80

COMMAND  PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   1208     root    7u  IPv4  10246      0t0  TCP *:http (LISTEN)
nginx   1208     root    8u  IPv6  10247      0t0  TCP *:http (LISTEN)
nginx   1209 www-data    7u  IPv4  10246      0t0  TCP *:http (LISTEN)
nginx   1209 www-data    8u  IPv6  10247      0t0  TCP *:http (LISTEN)
nginx   1210 www-data    7u  IPv4  10246      0t0  TCP *:http (LISTEN)
nginx   1210 www-data    8u  IPv6  10247      0t0  TCP *:http (LISTEN)

service nginx stop

lsof -i :80

COMMAND  PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   1208     root    7u  IPv4  10246      0t0  TCP *:http (LISTEN)
nginx   1208     root    8u  IPv6  10247      0t0  TCP *:http (LISTEN)
nginx   1209 www-data    7u  IPv4  10246      0t0  TCP *:http (LISTEN)
nginx   1209 www-data    8u  IPv6  10247      0t0  TCP *:http (LISTEN)
nginx   1210 www-data    7u  IPv4  10246      0t0  TCP *:http (LISTEN)
nginx   1210 www-data    8u  IPv6  10247      0t0  TCP *:http (LISTEN)

service nginx restart
 * Restarting nginx nginx
 ...fail!

错误日志:

2015/05/14 14:58:48 [emerg] 14620#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2015/05/14 14:58:48 [emerg] 14620#0: bind() to [::]:80 failed (98: Address already in use)
2015/05/14 14:58:48 [emerg] 14620#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2015/05/14 14:58:48 [emerg] 14620#0: bind() to [::]:80 failed (98: Address already in use)
2015/05/14 14:58:48 [emerg] 14620#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2015/05/14 14:58:48 [emerg] 14620#0: bind() to [::]:80 failed (98: Address already in use)
2015/05/14 14:58:48 [emerg] 14620#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2015/05/14 14:58:48 [emerg] 14620#0: bind() to [::]:80 failed (98: Address already in use)
2015/05/14 14:58:48 [emerg] 14620#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2015/05/14 14:58:48 [emerg] 14620#0: bind() to [::]:80 failed (98: Address already in use)
2015/05/14 14:58:48 [emerg] 14620#0: still could not bind()

Conf文件: nginx.conf

user www-data;
worker_processes 2;
pid /var/run/nginx.pid;

events {
    worker_connections 2048;
    use epoll;
    multi_accept on;
}

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 10;
    send_timeout 2;
    types_hash_max_size 2048;
    server_tokens off;

    client_max_body_size 5M;
    client_body_buffer_size 256k;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    #access_log /var/log/nginx/access.log;
    access_log off;
    error_log /var/log/nginx/error.log;

    gzip on;
    gzip_disable "msie6";
    proxy_set_header Accept-Encoding "";

    proxy_set_header Connection "";
    proxy_http_version 1.1;

    open_file_cache max=1000 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 5;
    open_file_cache_errors off;

    reset_timedout_connection on;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

位点可用/默认

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

    #listen [::]:80 ipv6only=on; # listen for IPv6 only traffic on IPv6 sockets
    #listen 80; # listen also for IPv4 traffic on "regular" IPv4 sockets

    root /usr/share/nginx/html;
    index index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }
}

0 个答案:

没有答案