【问题标题】:Location of Dash Plotly Flask WSGI error logging on Apache2Dash Plotly Flask WSGI 错误记录在 Apache2 上的位置
【发布时间】:2020-09-24 01:41:07
【问题描述】:

我有一个在 EC2 实例上运行的 Dash Plotly 应用程序。当我运行本地 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'

根据我的 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

【问题讨论】:

    标签: python flask apache2 mod-wsgi plotly-dash


    【解决方案1】:

    解决了。 /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'
    

    【讨论】:

      猜你喜欢
      • 2016-01-15
      • 2021-06-23
      • 2012-09-26
      • 2021-04-07
      • 2022-01-17
      • 1970-01-01
      • 2021-08-06
      • 2014-04-01
      • 2015-11-21
      相关资源
      最近更新 更多