烧瓶应用程序Apache部署(mod_wsgi)后,应用程序无响应

时间:2020-06-28 06:24:49

标签: apache flask deployment mod-wsgi

我正在尝试使用mod_wsgi将Flask应用程序部署在Apache Web服务器上。 部署后,当我转到配置为返回简单文本消息的“ healthCheck” URL时,该应用程序没有响应,并且正在超时。

这是我的wsgi文件:

<VirtualHost *:5000>
        ServerName <My ip address here>
        ServerAdmin admin@mywebsite.com
        WSGIScriptAlias / /var/www/ReleaseServices/ReleaseServices.wsgi
        <Directory /var/www/ReleaseServices/ReleaseServices/>
            Order allow,deny
            Allow from all
        </Directory>
        Alias /static /var/www/ReleaseServices/ReleaseServices/static
        <Directory /var/www/ReleaseServices/ReleaseServices/static/>
            Order allow,deny
            Allow from all
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

我在Apache日志中也看不到任何错误。可能是什么问题? 请问我是否需要其他详细信息。

1 个答案:

答案 0 :(得分:0)

所以我经过大量搜索后找到了解决方案。

我在我的 init .py 脚本中使用了scikit-learn,并且import语句导致问题并导致应用无响应。删除导入后,它工作正常。

当我寻找解决方案时,我发现了一些与WSGI配置有关的有趣事实,其中一个我错过了:

http://blog.rtwilson.com/how-to-fix-flask-wsgi-webapp-hanging-when-importing-a-module-such-as-numpy-or-matplotlib/

在该链接中,查看Graham Dumpleton的评论:

特定的解决方案是通过将应用程序组设置为%{GLOBAL}来强制使用主解释器。它记录在 http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Python_Simplified_GIL_State_API

基本上,您必须在.wsgi文件中添加以下行:

WSGIApplicationGroup%{GLOBAL}

这将强制特定的WSGI应用程序在初始化Python时创建的第一个Python子解释器中运行,从而解决了问题!

相关问题