我的 xubuntu 16.04 上的 apache 从休眠状态唤醒后无法工作。重新启动没有帮助。当我尝试重新启动时,我收到以下消息:
apache2.service 的作业失败,因为控制进程退出并显示错误代码。有关详细信息,请参阅“systemctl status apache2.service”和“journalctl -xe”。
尝试systemctl status apache2.service
返回
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: failed (Result: exit-code) since Sa 2016-08-20 21:24:49 CEST; 6min ago
Docs: man:systemd-sysv-generator(8)
Process: 6005 ExecStart=/etc/init.d/apache2 start (code=exited, status=1/FAILURE)
Aug 20 21:24:49 johndoe apache2[6005]: Output of config test was:
Aug 20 21:24:49 johndoe apache2[6005]: [Sat Aug 20 21:24:49.248413 2016] [core:crit] [pid 6015] (EAI 2)Name or service not known: AH00077: alloc_listener: failed to set up sockaddr for localhost
Aug 20 21:24:49 johndoe apache2[6005]: AH00526: Syntax error on line 5 of /etc/apache2/ports.conf:
Aug 20 21:24:49 johndoe apache2[6005]: Listen setup failed
Aug 20 21:24:49 johndoe apache2[6005]: Action 'configtest' failed.
Aug 20 21:24:49 johndoe apache2[6005]: The Apache error log may have more information.
Aug 20 21:24:49 johndoe systemd[1]: apache2.service: Control process exited, code=exited status=1
Aug 20 21:24:49 johndoe systemd[1]: Failed to start LSB: Apache2 web server.
Aug 20 21:24:49 johndoe systemd[1]: apache2.service: Unit entered failed state.
Aug 20 21:24:49 johndoe systemd[1]: apache2.service: Failed with result 'exit-code'.
提到的ports.conf
看起来不错(第 5 行是 Listen localhost:80):
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
Listen localhost:80
<IfModule ssl_module>
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
在error.log
答案1
域名(例如 localhost)和 IP 地址(例如 127.0.0.1)之间的连接是在/etc/hosts
(或在您的本地 DNS 服务器中)进行的。我认为配置错误是您无法让 Apache 监听域名(例如 localhost),但您必须使用 IP 地址。
要使 Apache 监听域名,您必须配置VirtualHost
(请参阅Apache 文档以获得解释)。
答案2
好吧,实际上是
Listen localhost:80
必须改为
Listen 80
我记得我曾经将其更改为 localhost:80 以限制来自外部的连接。也许由于最近的更新,它不再起作用了?我有 Apache/2.4.18
问题是,我现在不能使用 localhost 作为 url,我必须调用 127.0.0.1