Apache2 配置变量未定义

Apache2 配置变量未定义

我是 Apache2 的新手,所以请耐心等待。

我跟着让 HTTPS 与 Flask 服务器协同工作的教程。

当我运行该命令时,我不断得到相同的输出apache2

[Wed Nov 28 01:42:32.210442 2018] [core:warn] [pid 1184] AH00111: Config variable ${APACHE_PID_FILE} is not defined
[Wed Nov 28 01:42:32.210921 2018] [core:warn] [pid 1184] AH00111: Config variable ${APACHE_RUN_USER} is not defined
[Wed Nov 28 01:42:32.211029 2018] [core:warn] [pid 1184] AH00111: Config variable ${APACHE_RUN_GROUP} is not defined
[Wed Nov 28 01:42:32.211138 2018] [core:warn] [pid 1184] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Wed Nov 28 01:42:32.219990 2018] [core:warn] [pid 1184:tid 139772922629056] AH00111: Config variable ${APACHE_RUN_DIR} is not defined
[Wed Nov 28 01:42:32.220662 2018] [core:warn] [pid 1184:tid 139772922629056] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Wed Nov 28 01:42:32.221009 2018] [core:warn] [pid 1184:tid 139772922629056] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Wed Nov 28 01:42:32.221106 2018] [core:warn] [pid 1184:tid 139772922629056] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Wed Nov 28 01:42:32.221304 2018] [core:warn] [pid 1184:tid 139772922629056] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Wed Nov 28 01:42:32.221421 2018] [core:warn] [pid 1184:tid 139772922629056] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Wed Nov 28 01:42:32.221710 2018] [core:warn] [pid 1184:tid 139772922629056] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Wed Nov 28 01:42:32.221808 2018] [core:warn] [pid 1184:tid 139772922629056] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
AH00543: apache2: bad user name ${APACHE_RUN_USER}

我尝试了多个其他 StackOverflow、AskUbuntu 和 ServerFault 问题,但都没有帮助。我陷入困境,不知道该怎么办。我会将问题编辑为需要其他人提供的内容(例如代码或 conf 文件中的内容)

非常感谢您的任何帮助。

编辑:我访问了不安全(非 https)IP,得到了通用的 Apache“它起作用了!”页面。如果我访问安全(https)域,我会得到 500 内部服务器错误。

EDIT2:这是我当前的VirtualHost文件:

<VirtualHost *:80>
 ServerName xerix.me
 ServerAlias www.xerix.me
 ServerAdmin [email protected]
 WSGIScriptAlias / /var/www/cf/cf.wsgi
 <Directory /var/www/cf/cf/>
         Order allow,deny
         Allow from all
 </Directory>
 Alias /static /var/www/cf/cf/static
 <Directory /var/www/cf/cf/static/>
         Order allow,deny
         Allow from all
 </Directory>
 ErrorLog ${APACHE_LOG_DIR}/error.log
 LogLevel warn
 CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =xerix.me [OR]
RewriteCond %{SERVER_NAME} =www.xerix.me
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

编辑3:

Nov 28 01:50:34 xerix systemd[1]: Starting The Apache HTTP Server...
-- Subject: Unit apache2.service has begun start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit apache2.service has begun starting up.
Nov 28 01:50:34 xerix systemd[1]: Started The Apache HTTP Server.
-- Subject: Unit apache2.service has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit apache2.service has finished starting up.
-- 
-- The start-up result is RESULT.

编辑4:

[Wed Nov 28 02:43:15.319965 2018] [wsgi:error] [pid 2078:tid 139635571181312] [client :40218] Traceback (most recent call last):, referer: https://xerix.me/
[Wed Nov 28 02:43:15.320002 2018] [wsgi:error] [pid 2078:tid 139635571181312] [client :40218]   File "/var/www/cf/cf.wsgi", line 7, in <module>, referer: https://xerix.me/
[Wed Nov 28 02:43:15.320215 2018] [wsgi:error] [pid 2078:tid 139635571181312] [client :40218]     from cf import app as application, referer: https://xerix.me/
[Wed Nov 28 02:43:15.320252 2018] [wsgi:error] [pid 2078:tid 139635571181312] [client :40218] ImportError: cannot import name app, referer: https://xerix.me/

谢谢!

答案1

systemctl它应该在 Debian/Ubuntu 下以 root 身份启动。

/etc/init.d/apache2它也可以在 Debian/Ubuntu 下使用(又称旧命令)启动(系统范围)service,但现在最好的选择是使用 systemctl / systemd:

$ sudo systemctl start apache2.service

查看systemctl 手册页了解更多信息。

如果你坚持以非 root 用户身份运行它,>至少< 您需要先获取环境。

例如:

$ source /etc/apache2/envvars
$ apache2 -V | grep -i 'version\|mpm'
Server version: Apache/2.4.29 (Ubuntu)
Server MPM:     event

# or one line:
$ source /etc/apache2/envvars && apache2 -V | grep -i 'version\|mpm'
Server version: Apache/2.4.29 (Ubuntu)
Server MPM:     event

应该给你正确的输出(显示版本和 MPM 正在运行)。

在运行命令之前获取 Apache 变量可以正确读取/写入/解析所需的 Apache 文件/目录位置数据。

注意:大多数标志(例如apache2 -M(模块列表))将解析 Apache 配置文件和站点文件。如果文件/文件夹的读取仅限于 root,则以非 root 身份运行时会出现错误。您需要将 Apache 变量与命令一起使用sudo。(-V不解析配置 - 普通用户通常可以正常工作)。请参阅评论和https://serverfault.com/a/416613/92023

注意:您必须以 root 用户身份运行端口 80/443 上的 Web 服务。请参阅此回答了解原因。

只要首先获取当前运行环境,使用该命令将其作为守护进程/Web 服务(以 root 用户身份启动,无需初始化脚本)apache2也应该可以工作。我想不出这样做的充分理由。使用 systemctl 将其作为后台服务启动可以避免所有这些问题。

相关内容