我正在尝试启动安装在 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
列出文件的内容/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