环境

阿里云ubuntu版本:

LSB Version:    core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal

apache:

Server version: Apache/2.4.41 (Ubuntu)
Server built: 2020-08-12T19:46:17

报错

修改apache的配置文件后,重启apache会报错

#service apache2 restart

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

我这里出现过的错误:

错误1:

● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2021-05-31 21:00:24 CST; 3s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 1184602 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)

May 31 21:00:23 iZwz919g91pglb4zkj97ctZ systemd[1]: Starting The Apache HTTP Server...
May 31 21:00:24 iZwz919g91pglb4zkj97ctZ apachectl[1184611]: apache2: Syntax error on line 225 of /etc/apache2/apache2.conf: Syntax error on line 34 of /etc/apach>
May 31 21:00:24 iZwz919g91pglb4zkj97ctZ apachectl[1184602]: Action 'start' failed.
May 31 21:00:24 iZwz919g91pglb4zkj97ctZ apachectl[1184602]: The Apache error log may have more information.
May 31 21:00:24 iZwz919g91pglb4zkj97ctZ systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
May 31 21:00:24 iZwz919g91pglb4zkj97ctZ systemd[1]: apache2.service: Failed with result 'exit-code'.
May 31 21:00:24 iZwz919g91pglb4zkj97ctZ systemd[1]: Failed to start The Apache HTTP Server.

看后面log的第二行:

apache2: Syntax error on line 225 of /etc/apache2/apache2.conf: Syntax error on line 34 of /etc/apach>

进入配置文件中查看34行的错误,具体情况具体分析

错误2:

● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2021-05-31 21:04:16 CST; 14s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 1184995 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)

May 31 21:04:16 iZwz919g91pglb4zkj97ctZ systemd[1]: Starting The Apache HTTP Server...
May 31 21:04:16 iZwz919g91pglb4zkj97ctZ apachectl[1185012]: AH00526: Syntax error on line 37 of /etc/apache2/sites-enabled/000-default-ssl.conf:
May 31 21:04:16 iZwz919g91pglb4zkj97ctZ apachectl[1185012]: Invalid command 'ProxyRequests', perhaps misspelled or defined by a module not included in the server>
May 31 21:04:16 iZwz919g91pglb4zkj97ctZ apachectl[1184995]: Action 'start' failed.
May 31 21:04:16 iZwz919g91pglb4zkj97ctZ apachectl[1184995]: The Apache error log may have more information.
May 31 21:04:16 iZwz919g91pglb4zkj97ctZ systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
May 31 21:04:16 iZwz919g91pglb4zkj97ctZ systemd[1]: apache2.service: Failed with result 'exit-code'.
May 31 21:04:16 iZwz919g91pglb4zkj97ctZ systemd[1]: Failed to start The Apache HTTP Server.

依旧是看log的第二行,这次加上第三行:

May 31 21:04:16 iZwz919g91pglb4zkj97ctZ apachectl[1185012]: AH00526: Syntax error on line 37 of /etc/apache2/sites-enabled/000-default-ssl.conf:
May 31 21:04:16 iZwz919g91pglb4zkj97ctZ apachectl[1185012]: Invalid command 'ProxyRequests', perhaps misspelled or defined by a module not included in the server>

得知ProxyRequests模块未定义,这里是因为我配置了反向代理,然而它找不到模块。只需开启一下代理模块。

运行:

a2enmod proxy 

然后:

systemctl restart apache2

OK,成功运行!