Apache2上WSGI错误日志记录的位置

2024-04-19 16:03:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Dash Plotly应用程序在EC2实例上运行。当我运行本地Flask服务器时,我可以打开一个端口,代码在该端口号上运行。因此,我不会在控制台或页面上收到错误。但当我在实例的Apache2 WSGI服务器端口80上运行它时,该网页会在默认页面上报告一个内部服务器错误。但是,我在Apache2日志中找不到任何python错误:

sudo tail -100 /var/log/apache2/error.log

网页报告内部服务器错误次数的输出示例:

[Thu Jun 04 22:08:19.756897 2020] [mpm_event:notice] [pid 13197:tid 139903817145280] AH00491: caught SIGTERM, shutting down
[Thu Jun 04 22:08:19.825966 2020] [mpm_event:notice] [pid 13619:tid 140443934772160] AH00489: Apache/2.4.29 (Ubuntu) mod_wsgi/4.7.1 Python/3.7 configured -- resuming normal operations
[Thu Jun 04 22:08:19.826097 2020] [core:notice] [pid 13619:tid 140443934772160] AH00094: Command line: '/usr/sbin/apache2'
[Thu Jun 04 22:15:02.466329 2020] [mpm_event:notice] [pid 13619:tid 140443934772160] AH00491: caught SIGTERM, shutting down
[Thu Jun 04 22:15:02.543244 2020] [mpm_event:notice] [pid 13765:tid 140495801015232] AH00489: Apache/2.4.29 (Ubuntu) mod_wsgi/4.7.1 Python/3.7 configured -- resuming normal operations
[Thu Jun 04 22:15:02.543333 2020] [core:notice] [pid 13765:tid 140495801015232] AH00094: Command line: '/usr/sbin/apache2'

根据my FlaskApp.wsgi文件,错误收集在:

#!/usr/bin/python3
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/FlaskApp/")

from FlaskApp import server as application

Tags: 实例importeventwsgiusr错误syspid
1条回答
网友
1楼 · 发布于 2024-04-19 16:03:10

解决了。/etc/apache2/sites-available/FlaskApp.conf文件是设置实际日志输出目录和文件的位置:

<VirtualHost *:80>
                ServerName http://ec2-x-xxx-xx-xx.ap-northeast-1.compute.amazonaws.com
                ServerAdmin default@email.net
                WSGIScriptAlias / /var/www/FlaskApp/FlaskApp.wsgi
                <Directory /var/www/FlaskApp/FlaskApp/>
                        Order allow,deny
                        Allow from all
                </Directory>
                ErrorLog ${APACHE_LOG_DIR}/FlaskApp-error.log
                LogLevel warn
                CustomLog ${APACHE_LOG_DIR}/FlaskApp-access.log combined
</VirtualHost>

因此,在默认Apache2以root用户身份安装的情况下,输出位于: /var/log/apache2/FlaskApp-error.log

在这里,我可以访问python错误输出:

[Fri Jun 05 10:56:11.008176 2020] [wsgi:error] [pid 21235:tid 140495518934784] [client 77.160.155.4:47962] mod_wsgi (pid=21235): Failed to exec Python script file '/var/www/FlaskApp/FlaskApp.wsgi'.
[Fri Jun 05 10:56:11.008233 2020] [wsgi:error] [pid 21235:tid 140495518934784] [client 77.160.155.4:47962] mod_wsgi (pid=21235): Exception occurred processing WSGI script '/var/www/FlaskApp/FlaskApp.wsgi$
[Fri Jun 05 10:56:11.008315 2020] [wsgi:error] [pid 21235:tid 140495518934784] [client 77.160.155.4:47962] Traceback (most recent call last):
[Fri Jun 05 10:56:11.008344 2020] [wsgi:error] [pid 21235:tid 140495518934784] [client 77.160.155.4:47962]   File "/var/www/FlaskApp/FlaskApp.wsgi", line 7, in <module>
[Fri Jun 05 10:56:11.008349 2020] [wsgi:error] [pid 21235:tid 140495518934784] [client 77.160.155.4:47962]     from FlaskApp import server as application
[Fri Jun 05 10:56:11.008355 2020] [wsgi:error] [pid 21235:tid 140495518934784] [client 77.160.155.4:47962]   File "/var/www/FlaskApp/FlaskApp/__init__.py", line 7, in <module>
[Fri Jun 05 10:56:11.008358 2020] [wsgi:error] [pid 21235:tid 140495518934784] [client 77.160.155.4:47962]     from utils import Header, make_dash_table, table_link, pandas_shortener
[Fri Jun 05 10:56:11.008372 2020] [wsgi:error] [pid 21235:tid 140495518934784] [client 77.160.155.4:47962] ModuleNotFoundError: No module named 'utils'

相关问题 更多 >