Apache2伺服器無法啟動

Apache2伺服器無法啟動

我正在嘗試啟動安裝在 Ubuntu 22.04 LTS 桌面上的 apache2 伺服器。但是重啟失敗,從錯誤日誌中可以看到,這與我的配置有關。但是我無法進一步調試確切的問題。我的apache2伺服器配置如下。

cat /etc/apache2/sites-enabled/000-default.conf 
<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    WSGIDaemonProcess flaskapp threads=5 python-home=/home/hd2900/Documents/Python/hd2900TakeawayPrint/env
    WSGIScriptAlias / /home/hd2900/Documents/Python/hd2900TakeawayPrint/flaskapp.wsgi
    WSGIApplicationGroup %{GLOBAL}

    <Directory /home/hd2900/Documents/Python/hd2900TakeawayPrint>
              WSGIProcessGroup flaskapp
              Require all granted
    </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

當嘗試啟動伺服器時

sudo service apache2 restart
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xeu apache2.service" for details.

進一步挖掘 systemctl status apache2.service 似乎我的 apache2 設定檔中的第 18 行有問題。我已經檢查了該行,但無法確切看出問題所在。

systemctl status apache2.service
× apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2022-08-28 00:11:46 CEST; 1min 14s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 4561 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
        CPU: 66ms

Aug 28 00:11:45 hd2900 systemd[1]: Starting The Apache HTTP Server...
Aug 28 00:11:46 hd2900 apachectl[4564]: AH00526: Syntax error on line 18 of /etc/apache2/sites-enabled/000-default.conf:
Aug 28 00:11:46 hd2900 apachectl[4564]: Invalid command '\xe2\x80\x86', perhaps misspelled or defined by a module not included in the server configuration
Aug 28 00:11:46 hd2900 apachectl[4561]: Action 'start' failed.
Aug 28 00:11:46 hd2900 apachectl[4561]: The Apache error log may have more information.
Aug 28 00:11:46 hd2900 systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
Aug 28 00:11:46 hd2900 systemd[1]: apache2.service: Failed with result 'exit-code'.
Aug 28 00:11:46 hd2900 systemd[1]: Failed to start The Apache HTTP Server.

我還檢查了 error.log 並列印出以下內容。我仍然不確定確切的問題是什麼。

cat /var/log/apache2/error.log 
[Sat Aug 27 23:42:48.764507 2022] [mpm_event:notice] [pid 2886:tid 281473433382944] AH00489: Apache/2.4.52 (Ubuntu) configured -- resuming normal operations
[Sat Aug 27 23:42:48.765058 2022] [core:notice] [pid 2886:tid 281473433382944] AH00094: Command line: '/usr/sbin/apache2'
[Sat Aug 27 23:46:40.942688 2022] [mpm_event:notice] [pid 2886:tid 281473433382944] AH00492: caught SIGWINCH, shutting down gracefully
[Sat Aug 27 23:46:41.074596 2022] [mpm_event:notice] [pid 4010:tid 281473172430880] AH00489: Apache/2.4.52 (Ubuntu) mod_wsgi/4.9.0 Python/3.10 configured -- resuming normal operations
[Sat Aug 27 23:46:41.075061 2022] [core:notice] [pid 4010:tid 281473172430880] AH00094: Command line: '/usr/sbin/apache2'
[Sat Aug 27 23:52:16.956956 2022] [mpm_event:notice] [pid 4010:tid 281473172430880] AH00491: caught SIGTERM, shutting down

答案1

如果您使用該命令cat -tev而不是cat列出 file 的內容/etc/apache2/sites-enabled/000-default.conf,您將看到第 18 行和第 19 行包含一些奇怪的控製字符,如下所示:

[...]
    <Directory /home/hd2900/Documents/Python/hd2900TakeawayPrint>$
    M-bM-^@M-^F M-bM-^@M-^F M-bM-^@M-^F M-bM-^@M-^F M-bM-^@M-^F WSGIProcessGroup flaskapp$
    M-bM-^@M-^F M-bM-^@M-^F M-bM-^@M-^F M-bM-^@M-^F M-bM-^@M-^F Require all granted$
    </Directory>$
[...]

您可能已從 Web 或 PDF 頁面複製並貼上了這些指令。

您應該刪除該檔案的第 18 行和第 19 行,並在同一位置手動重新輸入設定指令:

WSGIProcessGroup flaskapp
Require all granted

相關內容