Apache 2无法绑定,地址已被使用。

我在 Ubuntu 12.10 上安装了 Apache 2。当我尝试使用 sudo /etc/init.d/apache2 start 启动服务时,我收到以下消息。

*Starting web server apache2
(98)Address already in use: make_sock: could not bind to address 127.0.0.1:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.                                 [fail]

1确保 Apache 在执行 (ps -ef | grep apache) 时没有正在运行。然后看一下 sudo /etc/init.d/apache2 restart 的输出是什么?验证一下在 /etc/apache2/sites-enabled/ 目录中是否有你的网站,并检查其中的文件。 - Rinzwind
5个回答

很有可能您已经有某些东西在该端口上运行(或“绑定”)。尝试使用以下命令来查看相关进程:
sudo lsof -i :80

这将列出在端口80上侦听的进程。一旦找到罪魁祸首,您就知道要终止哪个进程,可以使用killkill -9(也可作为超级用户)。
请注意,如果之前启动了Apache实例,则可能已经“过时”或变成僵尸。在后一种情况下,有时甚至可能需要重新启动。
否则,请遵循dedunumax的答案。

我已经安装了Apache和Nginx,之后移除了Nginx并修复了问题。 - Vahid Alvandi

尝试输入 sudo service apache2 start,然后按回车键。
sudo service apache2 status

第二个命令将显示它是否正在运行。

我在以下配置中收到了这个错误信息:
# cat /etc/hosts
127.0.0.1   localhost
127.0.0.1   foo
...

# cat /etc/apache2/sites-enabled/foo
<VirtualHost foo:80>
...

# cat /etc/apache2/ports.conf 
...
NameVirtualHost *:80
Listen localhost:80
...

ports.conf 更改为以下内容解决了问题:
NameVirtualHost *:80
Listen 127.0.0.1:80

可能有其他软件如Nginx正在运行并使用端口80。

Apache2在我的VPS上出现了相同的错误消息导致崩溃,我发现服务器上存在着Nginx,并且几天后某个东西(一个cron作业?)启动了它。这会导致冲突,因为它使用的是端口:80,并且以某种方式优先于Apache2。

要检查是否已经有任何东西使用端口:80,请输入:

netstat -tulpn

我通过卸载Nginx(使用"remove --purge"命令),终止Nginx进程,并重新启动Apache2来解决了这个问题。

我在配置中遇到了这个Apache错误消息。
# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

我将::1条目注释掉并执行了一个Apache重启命令。
# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
#::1         localhost localhost.localdomain localhost6 localhost6.localdomain6


# sudo service httpd restart