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

2014-08-15 15:17:01 +08:00
 Nickyu
是按照这个教程来的
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;
# }
#}

}
请问,这要怎么解决啊
20420 次点击
所在节点    问与答
19 条回复
msg7086
2014-08-15 15:17:44 +08:00
先看看你80端口上跑了什么东西……
Nickyu
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
2014-08-15 15:21:02 +08:00
还好我看懂了already in use...
Nickyu
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
2014-08-15 15:24:23 +08:00
@Nickyu netstat -tnpl 看看是什么东西在80端口运行
phperstar
2014-08-15 15:28:53 +08:00
先ps aux 看一下有没有未结束的进程,然后 pgrep php-cgi | xargs kill -s 9 ,最后重启
Nickyu
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
2014-08-15 15:34:05 +08:00
你怎么重启的? `sudo nginx` ?
Nickyu
2014-08-15 15:37:18 +08:00
@582033 nginx -s reopen ,有问题?
ooxxcc
2014-08-15 15:41:07 +08:00
mac下使用80端口似乎需要sudo
Nickyu
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
2014-08-15 16:27:41 +08:00
sudo nginx
freetg
2014-08-15 16:35:59 +08:00
@Nickyu http就是80
Nickyu
2014-08-15 16:48:00 +08:00
@ooxxcc 没用,返回的是failed 48:already in use,好像是nginx自己占用端口,但是kill 掉80端口重启nginx还是这样
Nickyu
2014-08-15 16:50:58 +08:00
@ooxxcc 浏览器输入local地址后还是404 not found nginx/1.6.1
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
2014-08-15 18:39:50 +08:00
80端口被占用了?如果centos的话记得卸载Apache
syaokun219
2014-08-15 22:35:05 +08:00
感觉像是一个很普通的问题
itfanr
2014-12-14 22:16:20 +08:00
请问楼主后来解决了吗?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/128080

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX