无法在Ubuntu 12.10上启动Apache:没有可用的监听套接字


9

我无法启动使用apt-get安装的apache2。我在2个单独的Ubuntu 12.10安装上遇到了相同的错误,一个安装在台式机上,另一个安装在VirtualBox中运行:

michal@michaltest:~$ sudo service apache2 start
 * Starting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.
           [fail]

lsof说:

michal@michaltest:/var/log/apache2$ sudo lsof -i :80
COMMAND     PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
ubuntu-ge  2074 michal   11u  IPv4  23978      0t0  TCP michaltest.local:47578->mulberry.canonical.com:http (CLOSE_WAIT)
firefox   25194 michal   71u  IPv4  42477      0t0  TCP michaltest.local:59793->69.59.197.29:http (ESTABLISHED)
firefox   25194 michal   76u  IPv4  41834      0t0  TCP michaltest.local:59698->69.59.197.29:http (ESTABLISHED)
gvfsd-htt 25320 michal   12u  IPv4  42568      0t0  TCP michaltest.local:56203->lb260.amst.cotendo.net:http (CLOSE_WAIT)

netstat说:

michal@michaltest:/var/log/apache2$ sudo netstat -lnp | grep '80'
unix  2      [ ACC ]     STREAM     LISTENING     8030     876/acpid           /var/run/acpid.socket

/var/log/apache2/error.log:

[Thu Nov 08 11:13:30 2012] [notice] Apache/2.2.22 (Ubuntu) configured -- resuming normal operations
[Thu Nov 08 11:17:32 2012] [notice] caught SIGTERM, shutting down

/etc/apache2/ports.conf:

NameVirtualHost *:80
Listen 80

<IfModule mod_ssl.c>
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

谢谢你的帮助。

编辑#1:

michal@michaltest:~$ sudo netstat -ano | grep '443'
tcp       54      0 10.0.2.15:58504         91.189.92.70:443        CLOSE_WAIT  off (0.00/0/0)

Answers:


9

您只需要删除nginx(3个程序包),就可以了.....

您的主要问题是没有可用的侦听套接字。您面临此问题,因为另一个应用程序/服务在Ubuntu Server上获取了端口80

现在您需要终止获取端口80的进程。您可以使用以下命令轻松找到它:-

须藤netstat -ltnp | grep':80'

这将返回类似:

tcp 0 0 127.0.0.1:80 0.0.0.0:* LISTEN 1588 / aolserver4-nsd

对于上述情况,进程号1588获得了端口80,则需要终止该进程1588。

须藤杀-9 1588

现在,您可以通过以下命令启动apache服务器

sudo /etc/init.d/apache2开始


3
谢谢!这让我有些难过,因为它说“ Apache错误日志可能包含更多信息”,但是里面什么也没有,也“无法打开日志”,但是却没有哪个日志文件(apache的?vhosts? )。原来,是的NodeJS仍然使用端口80 ..
andyk

我收到相同的错误,但是netstat使用端口80没有列出任何东西……
Cerin

@Cerin您应该在netstat之前尝试sudo。
Vikas Dwivedi

2

要解决“ apache2:无法对ServerName使用127.0.1.1可靠地确定服务器的标准域名”的错误,请在apache2.conf文件中指定以下内容

ServerName HOSTNAME_OF_THE_SERVER

保存conf文件并重新启动apache服务器。

请张贴的输出 sudo netstat -ano | grep '443'

还要确保,如果您将apache配置为侦听443 / ssl端口,则应在apache Web服务器上配置ssl证书。


我发布了的输出sudo netstat -ano | grep '443'。ServerName并不是问题。非常感谢你。
michalstanko


1

似乎可能正在运行Nginx服务。因此,停止nginx“ service nginx stop”,现在尝试启动apache2服务,它应该没有任何问题。(如果正在运行任何其他应用程序服务,则停止)

今天我遇到了同样的问题,并且得到解决。

root@ip-172-31-16-xxx:~# **service nginx stop**
root@ip-172-31-16-xxx:~# **service nginx status**
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Tue 2017-12-26 08:48:21 UTC; 1min 12s ago
  Process: 5897 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 1220 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 1158 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 1229 (code=exited, status=0/SUCCESS)

Dec 26 06:56:32 ip-172-31-16-xxxsystemd[1]: Starting A high performance web server and a reverse proxy server...
Dec 26 06:56:32 ip-172-31-16-138 systemd[1]: Started A high performance web server and a reverse proxy server.
Dec 26 08:48:21 ip-172-31-16-138 systemd[1]: Stopping A high performance web server and a reverse proxy server...
Dec 26 08:48:21 ip-172-31-16-138 systemd[1]: Stopped A high performance web server and a reverse proxy server.

root@ip-172-31-16-xxx:~# **service apache2 start**
root@ip-172-31-16-xxx:~# **service apache2 status**
● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   **Active: active (running) since Tue 2017-12-26 08:49:51 UTC; 14s ago**
     Docs: man:systemd-sysv-generator(8)
  Process: 5845 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
  Process: 5937 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS)
    Tasks: 55
   Memory: 6.5M
      CPU: 46ms
   CGroup: /system.slice/apache2.service
           ├─5954 /usr/sbin/apache2 -k start
           ├─5957 /usr/sbin/apache2 -k start
           └─5958 /usr/sbin/apache2 -k start

Dec 26 08:49:50 ip-172-31-16-138 systemd[1]: Starting LSB: Apache2 web server...
Dec 26 08:49:50 ip-172-31-16-138 apache2[5937]:  * Starting Apache httpd web server apache2
Dec 26 08:49:51 ip-172-31-16-138 apache2[5937]:  *
Dec 26 08:49:51 ip-172-31-16-138 systemd[1]: Started LSB: Apache2 web server.
root@ip-172-31-16-138:~#

0

听起来问题是另一个进程打开了端口443。您需要先终止该过程。

linux-如何删除CLOSE_WAIT套接字连接-堆栈溢出说:

CLOSE_WAIT表示您的程序仍在运行,并且尚未关闭套接字(内核正在等待它关闭)。添加-pnetstat以获取该pid,然后更加有力地将其杀死(SIGKILL如果需要,可以将其删除)。那应该摆脱您的CLOSE_WAIT套接字。您也可以使用ps来查找pid。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.