我尝试使用 VirtualHosts (Apache2) 在我的 EC2 实例上配置托管 2 个网站。设置两个 VirtualHosts 后,我无法重新启动 apache2 服务。当我尝试这样做时,我收到此错误:
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.
“systemctl status apache2.service”返回以下内容:
* apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
`-apache2-systemd.conf
Active: failed (Result: exit-code) since Mon 2020-05-11 16:51:42 UTC; 1min 2s ago
Process: 18831 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
Main PID: 27500 (code=exited, status=0/SUCCESS)
May 11 16:51:42 ip-172-31-39-99 systemd[1]: Starting The Apache HTTP Server...
May 11 16:51:42 ip-172-31-39-99 apachectl[18831]: Action 'start' failed.
May 11 16:51:42 ip-172-31-39-99 apachectl[18831]: The Apache error log may have more information.
May 11 16:51:42 ip-172-31-39-99 systemd[1]: apache2.service: Control process exited, code=exited status=1
May 11 16:51:42 ip-172-31-39-99 systemd[1]: apache2.service: Failed with result 'exit-code'.
May 11 16:51:42 ip-172-31-39-99 systemd[1]: Failed to start The Apache HTTP Server.
并且“journalctl -xe”返回以下内容:
-- Unit apache2.service has begun starting up.
May 11 16:51:42 ip-172-31-39-99 apachectl[18831]: Action 'start' failed.
May 11 16:51:42 ip-172-31-39-99 apachectl[18831]: The Apache error log may have more information.
May 11 16:51:42 ip-172-31-39-99 systemd[1]: apache2.service: Control process exited, code=exited status=1
May 11 16:51:42 ip-172-31-39-99 sudo[18828]: pam_unix(sudo:session): session closed for user root
May 11 16:51:42 ip-172-31-39-99 systemd[1]: apache2.service: Failed with result 'exit-code'.
May 11 16:51:42 ip-172-31-39-99 systemd[1]: Failed to start The Apache HTTP Server.
-- Subject: Unit apache2.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit apache2.service has failed.
--
-- The result is RESULT.
May 11 16:51:59 ip-172-31-39-99 sshd[18868]: Invalid user www from 69.158.207.141 port 51665
May 11 16:51:59 ip-172-31-39-99 sshd[18868]: Received disconnect from 69.158.207.141 port 51665:11: Normal Shutdown, Thank you for playing [preauth]
May 11 16:51:59 ip-172-31-39-99 sshd[18868]: Disconnected from invalid user www 69.158.207.141 port 51665 [preauth]
May 11 16:52:35 ip-172-31-39-99 sshd[18870]: Invalid user demo from 69.158.207.141 port 56795
May 11 16:52:35 ip-172-31-39-99 sshd[18870]: Received disconnect from 69.158.207.141 port 56795:11: Normal Shutdown, Thank you for playing [preauth]
May 11 16:52:35 ip-172-31-39-99 sshd[18870]: Disconnected from invalid user demo 69.158.207.141 port 56795 [preauth]
May 11 16:53:11 ip-172-31-39-99 sshd[18875]: Invalid user zhangfeng from 69.158.207.141 port 33692
May 11 16:53:11 ip-172-31-39-99 sshd[18875]: Received disconnect from 69.158.207.141 port 33692:11: Normal Shutdown, Thank you for playing [preauth]
May 11 16:53:11 ip-172-31-39-99 sshd[18875]: Disconnected from invalid user zhangfeng 69.158.207.141 port 33692 [preauth]
May 11 16:53:47 ip-172-31-39-99 sshd[18878]: Invalid user centos from 69.158.207.141 port 38822
May 11 16:53:47 ip-172-31-39-99 sshd[18878]: Received disconnect from 69.158.207.141 port 38822:11: Normal Shutdown, Thank you for playing [preauth]
May 11 16:53:47 ip-172-31-39-99 sshd[18878]: Disconnected from invalid user centos 69.158.207.141 port 38822 [preauth]
May 11 16:53:58 ip-172-31-39-99 sshd[18880]: Received disconnect from 222.186.30.35 port 47135:11: [preauth]
May 11 16:53:58 ip-172-31-39-99 sshd[18880]: Disconnected from authenticating user root 222.186.30.35 port 47135 [preauth]
我四处查看,发现有人告诉我运行“apache2ctl configtest”会返回“Syntax OK”。有人运行“apache2 --help”会返回更多错误信息,结果如下:
(13)Permission denied: AH00072: make_sock: could not bind to address [::]:80
(13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
进一步查看后,我被告知使用“sudo apache2 --help”,但出现以下错误:
[Mon May 11 17:01:39.505293 2020] [core:warn] [pid 18920] AH00111: Config variable ${APACHE_RUN_DIR} is not defined
apache2: Syntax error on line 80 of /etc/apache2/apache2.conf: DefaultRuntimeDir must be a valid directory, absolute or relative to ServerRoot
但是 Apache2 已正确安装,我尝试了“source /etc/apache2/envvars”,但似乎没有任何作用。为什么会出现此错误?我该如何解决?你们能帮我吗?提前谢谢。