Apache无法启动,地址已在使用中(但不是真的)

我正在尝试设置运行Ubuntu 12.04的VM。 我有两个使用端口80配置的虚拟主机,但Apache无法启动。

我收到此错误:
(98) Address already in use: make_sock: could not bind to address 0.0.0.0:80

netstat -tulpn的输出显示没有使用端口80.可能导致这种情况的原因是什么?

确保您没有在.conf文件中声明Listen 80两次。

例如,您可能在ports.conf和inn sites-enabled/www.conf都有它。

要找到grep -ri listen /etc/apache2 ,请使用: grep -ri listen /etc/apache2

Listen 80放在一个地方。

回答我解决这个问题的方式。 将来可能对某人有所帮助。

试试netstat -ltnp | grep :80 netstat -ltnp | grep :80

这将返回类似的东西

tcp6 0 0 ::: 80 ::: * LISTEN 1047 / apache2

然后跑

 sudo kill -9 1047 

其中1047是在端口80上运行的程序的pid。您可以替换从netstat获得的pid

当我遇到这个问题时,原来是因为我的Apache无法启动,因为我有一个SSL站点,需要为证书输入密码。

判断这是否适合您的一个好方法是运行ps -ef | grep apache ps -ef | grep apache :如果这返回的进程看起来像/bin/bash /usr/share/apache2/ask-for-passphrase mysite.com:443 RSA那么它正在等待一个你永远不会看到的终端输入密码。

首先,我杀死了挂起的进程(发送一个kill -HUP到/ usr / sbin / apache2进程的进程ID应该足以杀死其他进程,但是要做另一个ps -ef | grep apache来确定)。

然后我按照这篇文章中的说明创建了一个不需要输入密码的SSL密码文件。 然后service apache2 start工作正常,Apache重启后正常启动。

启动apache2 Ubuntu 12.10时,我在全新安装时遇到此错误。

这是apache2中的一个错误。 它挂在后台。 以下是我在软件中可能出现错误的演练。

这是我得到的错误:

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

地址已在使用中? 什么可以使用它? 看看这个:

 el@titan:~$ grep -ri listen /etc/apache2 /etc/apache2/apache2.conf:# supposed to determine listening ports for incoming connections, and which /etc/apache2/apache2.conf:# Include list of ports to listen on and which to use for name based vhosts /etc/apache2/ports.conf:Listen 80 /etc/apache2/ports.conf: Listen 443 /etc/apache2/ports.conf: Listen 443 

这意味着apache2阻止apache2启动。 离奇。 这将证实:

 el@titan:~$ ps -ef | grep apache2 root 1146 954 0 15:51 ? 00:00:00 /bin/sh /etc/rc2.d/S91apache2 start root 1172 1146 0 15:51 ? 00:00:00 /bin/sh /usr/sbin/apache2ctl start root 1181 1172 0 15:51 ? 00:00:00 /usr/sbin/apache2 -k start root 1193 1181 0 15:51 ? 00:00:00 /bin/bash /usr/share/apache2/ask-for-passphrase 127.0.1.1:443 RSA el 5439 5326 0 16:23 pts/2 00:00:00 grep --color=auto apache2 

是的,在这种情况下apache2正在运行,我试图在同一个端口上第二次启动apache2。

令我困惑的是service报告apache2没有运行:

 el@titan:~$ sudo service apache2 status Apache2 is NOT running. 

当您查询apache2ctl的状态时,它会挂起。

 root@titan:~# /usr/sbin/apache2ctl status **hangs until Ctrl-C is pressed. 

所以Ubuntu在启动时似乎无法管理apache2。 是时候停止apache2了:

 root@titan:~# /usr/sbin/apache2ctl stop httpd (no pid file) not running 

一个很大的线索! 你试图阻止apache2,它失去了进程ID! 所以Ubuntu无法阻止apache2,因为它不知道它在哪里!

你会认为重启会修复它,但它不会因为apache2在启动时启动并挂起。 apache2的正常启动过程无法正常工作。

那么如何解决呢?

我能够通过分析ps命令输出来解决这个问题 。 请注意, ps命令告诉我们该进程是由“/etc/rc2.d/S91apache2 start”启动的。

这是一个需要快速踢球的违规计划。

/etc/rc2.d/S91apache2是用于在计算机启动时为您启动apache2的符号链接。 出于某种原因,它似乎是启动apache2然后挂起。 所以我们必须告诉它不要这样做。

那么去看看/etc/rc2.d/S91apache2

 el@titan:/etc/rc2.d$ ls -l lrwxrwxrwx 1 root root 17 Nov 7 21:45 S91apache2 -> ../init.d/apache2* 

这是一个象征性的链接,我们不希望它在那里。 这样做是为了防止apache2在启动时启动:

 root@titan:~# sudo update-rc.d -f apache2 remove Removing any system startup links for /etc/init.d/apache2 ... /etc/rc0.d/K09apache2 /etc/rc1.d/K09apache2 /etc/rc2.d/S91apache2 /etc/rc3.d/S91apache2 /etc/rc4.d/S91apache2 /etc/rc5.d/S91apache2 /etc/rc6.d/K09apache2 

重新启动计算机以确保apache2无法启动并挂起。 好的 现在你可以把apache2放回原来的样子,但这会让它再次失败。

 root@titan:~$ sudo update-rc.d apache2 defaults //(don't do this) Adding system startup for /etc/init.d/apache2 ... /etc/rc0.d/K20apache2 -> ../init.d/apache2 /etc/rc1.d/K20apache2 -> ../init.d/apache2 /etc/rc6.d/K20apache2 -> ../init.d/apache2 /etc/rc2.d/S20apache2 -> ../init.d/apache2 /etc/rc3.d/S20apache2 -> ../init.d/apache2 /etc/rc4.d/S20apache2 -> ../init.d/apache2 /etc/rc5.d/S20apache2 -> ../init.d/apache2 

相反,像这样启动apache2:

 sudo service apache2 start 

并且apache2已备份并再次提供页面服务。 apache2 / Ubuntu 12.10似乎有一些严重的错误导致apache2启动并挂起。 这是一种解决方法,我想修复是为了获得更新版本的apache2和Ubuntu并希望最好。

我在我的AWS EC2服务器上监听Nginx服务器,我认为它在构建EC2时已经配置,因此我得到了Address已经在使用中的错误。 所以我停止了服务并启动了Apache2服务:

 sudo service nginx stop sudo service apache2 start 

我已经弄清楚了。 我在httpd.conf和ports.conf中都有重复的Listen 80命令

此外,在为正在虚拟化的服务器复制配置文件时,我忽略了错误日志目录已被更改。 查看该错误日志,我注意到我的httpd.conf文件中mime.types配置文件的目录不正确。 我更新了该参数,服务器启动正常。

这意味着您已经使用了端口80,或者通过编辑更改apache2的端口(我不建议这样做):

 /etc/apache2/ports.conf 

或者关闭在端口80上运行的应用程序:

 netstat -antp | grep 80 

查找端口80上正在运行的内容。

只是暗示任何人,他们可能正在运行带有NAT网络的VirtualBox。 我发现,在我的访客和主机之间有一个NAT规则设置了自己,绑定了端口

不只是重复提及

 Listen 80 

除了Listen 80之外,还要提到这一点

 Include ports.conf