V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
Nickyu
V2EX  ›  问与答

nginx 启动不了 nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)

  •  
  •   Nickyu · 2014-08-15 15:17:01 +08:00 · 20417 次点击
    这是一个创建于 3754 天前的主题,其中的信息可能已经有所发展或是发生改变。
    是按照这个教程来的
    https://coderwall.com/p/dgwwuq
    但是安装完nginx后启动就出现这个错误
    Nicks-MacBook-Pro:~ Nick$ sudo nginx
    nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)

    这是nginx.conf配置内容

    #user nobody;
    worker_processes 1;

    #error_log logs/error.log;
    #error_log logs/error.log notice;
    #error_log logs/error.log info;

    #pid logs/nginx.pid;


    events {
    worker_connections 1024;
    }


    http {
    include mime.types;
    default_type application/octet-stream;

    #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    # '$status $body_bytes_sent "$http_referer" '
    # '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log logs/access.log main;

    sendfile on;
    #tcp_nopush on;

    #keepalive_timeout 0;
    keepalive_timeout 65;

    #gzip on;

    server {
    listen 80;
    server_name localhost;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location / {
    root /Users/to/www;
    index index.html index.htm;
    }

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    # proxy_pass http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    # root html;
    # fastcgi_pass 127.0.0.1:9000;
    # fastcgi_index index.php;
    # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    # include fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    # deny all;
    #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    # listen 8000;
    # listen somename:8080;
    # server_name somename alias another.alias;

    # location / {
    # root html;
    # index index.html index.htm;
    # }
    #}


    # HTTPS server
    #
    #server {
    # listen 443 ssl;
    # server_name localhost;

    # ssl_certificate cert.pem;
    # ssl_certificate_key cert.key;

    # ssl_session_cache shared:SSL:1m;
    # ssl_session_timeout 5m;

    # ssl_ciphers HIGH:!aNULL:!MD5;
    # ssl_prefer_server_ciphers on;

    # location / {
    # root html;
    # index index.html index.htm;
    # }
    #}

    }
    请问,这要怎么解决啊
    19 条回复    2014-12-14 22:16:20 +08:00
    msg7086
        1
    msg7086  
       2014-08-15 15:17:44 +08:00
    先看看你80端口上跑了什么东西……
    Nickyu
        2
    Nickyu  
    OP
       2014-08-15 15:20:42 +08:00
    @msg7086 /Users/Nick/Desktop/Screen Shot 2014-08-15 at 3.20.04 PM.png
    只有这个,但是kill掉后重启还是这样啊
    582033
        3
    582033  
       2014-08-15 15:21:02 +08:00
    还好我看懂了already in use...
    Nickyu
        4
    Nickyu  
    OP
       2014-08-15 15:21:36 +08:00
    @msg7086 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
    com.apple 244 Nick 17u IPv4 0xcae88a86e6df724d 0t0 TCP 192.168.1.102:53372->203.208.41.131:http (ESTABLISHED)
    com.apple 244 Nick 20u IPv4 0xcae88a86e6df724d 0t0 TCP 192.168.1.102:53372->203.208.41.131:http (ESTABLISHED)
    nginx 11536 root 6u IPv4 0xcae88a86ed3ae24d 0t0 TCP *:http (LISTEN)
    nginx 11537 nobody 6u IPv4 0xcae88a86ed3ae24d 0t0 TCP *:http (LISTEN)
    582033
        5
    582033  
       2014-08-15 15:24:23 +08:00
    @Nickyu netstat -tnpl 看看是什么东西在80端口运行
    phperstar
        6
    phperstar  
       2014-08-15 15:28:53 +08:00
    先ps aux 看一下有没有未结束的进程,然后 pgrep php-cgi | xargs kill -s 9 ,最后重启
    Nickyu
        7
    Nickyu  
    OP
       2014-08-15 15:29:06 +08:00
    @582033 没看到啊,我用这个命令看的时候terminal是这么显示的
    Nicks-MacBook-Pro:~ Nick$ sudo lsof -i:80
    Password:
    COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
    nginx 11536 root 6u IPv4 0xcae88a86ed3ae24d 0t0 TCP *:http (LISTEN)
    nginx 11537 nobody 6u IPv4 0xcae88a86ed3ae24d 0t0 TCP *:http (LISTEN)
    582033
        8
    582033  
       2014-08-15 15:34:05 +08:00
    你怎么重启的? `sudo nginx` ?
    Nickyu
        9
    Nickyu  
    OP
       2014-08-15 15:37:18 +08:00
    @582033 nginx -s reopen ,有问题?
    ooxxcc
        10
    ooxxcc  
       2014-08-15 15:41:07 +08:00
    mac下使用80端口似乎需要sudo
    Nickyu
        11
    Nickyu  
    OP
       2014-08-15 15:42:55 +08:00
    @ooxxcc 我加了,不加不行的,然后就这样了,Nicks-MacBook-Pro:~ Nick$ sudo -s reopen
    /bin/bash: reopen: command not found
    Nicks-MacBook-Pro:~ Nick$ sudo nginx -s reopen
    nginx: [alert] kill(11536, 30) failed (3: No such process)
    搞不懂啊
    ooxxcc
        12
    ooxxcc  
       2014-08-15 16:27:41 +08:00
    sudo nginx
    freetg
        13
    freetg  
       2014-08-15 16:35:59 +08:00
    @Nickyu http就是80
    Nickyu
        14
    Nickyu  
    OP
       2014-08-15 16:48:00 +08:00
    @ooxxcc 没用,返回的是failed 48:already in use,好像是nginx自己占用端口,但是kill 掉80端口重启nginx还是这样
    Nickyu
        15
    Nickyu  
    OP
       2014-08-15 16:50:58 +08:00
    @ooxxcc 浏览器输入local地址后还是404 not found nginx/1.6.1
    ooxxcc
        16
    ooxxcc  
       2014-08-15 17:06:21 +08:00
    @Nickyu nginx默认的配置文件应该是 http://localhost:8080/,我这边测试可以

    试试sudo killall nginx ; sudo nginx -c /xxx/xxx/nginx.conf

    nginx version: nginx/1.6.1
    Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]

    Options:
    -?,-h : this help
    ...
    -s signal : send signal to a master process: stop, quit, reopen, reload
    -p prefix : set prefix path (default: /usr/local/Cellar/nginx/1.6.1/)
    -c filename : set configuration file (default: /usr/local/etc/nginx/nginx.conf)
    zts1993
        17
    zts1993  
       2014-08-15 18:39:50 +08:00 via Android
    80端口被占用了?如果centos的话记得卸载Apache
    syaokun219
        18
    syaokun219  
       2014-08-15 22:35:05 +08:00 via iPhone
    感觉像是一个很普通的问题
    itfanr
        19
    itfanr  
       2014-12-14 22:16:20 +08:00
    请问楼主后来解决了吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2861 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 12:33 · PVG 20:33 · LAX 04:33 · JFK 07:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.