我正在尝试在 Ubuntu 11.04 上设置 nginx。我大致遵循了此处的说明:http://library.linode.com/frameworks/sinatra/debian-6-squeeze。我知道它是为 Debian 准备的,但我基本上是按照那些步骤然后在 google 上搜索“如何在 ubuntu 11.04 中执行 x”虽然我确实从他们的库中提取了 init 脚本。
Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
命令:“sudo lsof -i:80”未返回端口 80 上任何正在运行的内容。
我该如何解决这个问题或者对可能出现的问题有什么想法?
我看见在全新安装的 Ubuntu 上安装 Nginx + uWSGI - 绑定错误端口 80尝试重启电脑并运行一次,结果还是同样的错误。运行一次后,我又运行了 lsof 命令。
更新
sudo netstat -ltnp 返回:
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address
Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1998/sshd
tcp6 0 0 :::22 :::* LISTEN 1998/sshd
nestat -a 返回:
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:ssh *:* LISTEN
tcp 0 176 matterhorn.noahc.ne:ssh 173-26-190-206.cl:26467 ESTABLISHED
tcp6 0 0 [::]:ssh [::]:* LISTEN
udp 0 0 matterhorn.noahc.:35332 10504.x.rootbsd.net:ntp ESTABLISHED
udp 0 0 matterhorn.noahc.:53298 tick.tadatv.com:ntp ESTABLISHED
udp 0 0 matterhorn.noahc.:54371 ns1.baribault.net:ntp ESTABLISHED
udp 0 0 matterhorn.noahc.:38304 tardis.chpc.utah.ed:ntp ESTABLISHED
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 684 @/com/ubuntu/upstart
unix 2 [ ] DGRAM 730 @/org/kernel/udev/udevd
unix 6 [ ] DGRAM 4316 /dev/log
unix 2 [ ] DGRAM 11447
unix 3 [ ] STREAM CONNECTED 10466
unix 3 [ ] STREAM CONNECTED 10465
unix 2 [ ] DGRAM 11411
unix 3 [ ] STREAM CONNECTED 2958
unix 3 [ ] STREAM CONNECTED 2957
unix 2 [ ] DGRAM 4518
unix 2 [ ] DGRAM 2902
unix 2 [ ] DGRAM 2614
unix 3 [ ] STREAM CONNECTED 1284 @/com/ubuntu/upstart
unix 3 [ ] STREAM CONNECTED 4131
unix 3 [ ] DGRAM 733
unix 3 [ ] DGRAM 732
unix 3 [ ] STREAM CONNECTED 1038 @/com/ubuntu/upstart
unix 3 [ ] STREAM CONNECTED 2088
答案1
一种可能性是,由于某种原因,nginx 两次绑定到端口 80。
如果它尝试这样做,它将失败。例如,绑定到 IPV6 和 IPV4,或将其绑定到公共 IP 和通配符 IP。
检查你的 nginx 配置以确保它只绑定一次。
答案2
尝试:
http{
server {
listen 80;
listen localhost; # <- probably will fix your problem
location / {
root /data/www;
}
location /images/ {
root /data;
}
}
}
答案3
如果您的服务器块没有 listen 指令,Nginx 将默认为 80。