无法在Flask设置中解决mod_wsgi异常

x

我想使用Python 3部署Flask应用程序。我正在运行Ubuntu 16.04,Apache2。

我运行sudo apt-get install libapache2-mod-wsgi-py3来安装wsgi。

我按照这里的指示进行我的Linode服务器上的/var/www/html/hxueh.net/finance有一个Flask应用程序。财务文件夹内有一个文件和一个文件夹。结构看起来像这样。

|--------finance
|----------------finance
|-----------------------static
|-----------------------templates
|-----------------------venv
|-----------------------application.py
|----------------finance.wsgi

在venv / bin中:

activate activate_this.py flask pip3.5 python3.5
activate.csh easy_install pip python python-config
activate.fish easy_install-3.5 pip3 python3 wheel

finance.wsgi是:

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

from finance import app as application

我的Apache2配置是:

<VirtualHost *:80>
        ServerName finance.hxueh.net
        ServerAdmin [email protected]
        WSGIScriptAlias / /var/www/html/hxueh.net/finance/finance.wsgi
        <Directory /var/www/html/hxueh.net/finance/finance/>
                Order allow,deny
                Allow from all
        </Directory>
        <Directory /var/www/html/hxueh.net/finance>
                WSGIProcessGroup finance
                WSGIApplicationGroup %{GLOBAL}
                Order deny,allow
                Allow from all
        </Directory>
        Alias /static /var/www/html/hxueh.net/finance/finance/static
        <Directory /var/www/html/hxueh.net/finance/finance/static/>
                Order allow,deny
                Allow from all
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

我有一个在同一服务器上运行的Wordpress应用程序,并且Certbot启用了“让我们加密证书”。

当我访问服务器时,它返回错误500。在error.log中,它显示:

[Sun Jan 21 10:40:56.310304 2018] [mpm_prefork:notice] [pid 26281] AH00169: caught SIGTERM, shutting down
[Sun Jan 21 10:41:21.236671 2018] [ssl:warn] [pid 26747] AH01909: hxueh.net:443:0 server certificate does NOT include an ID which matches the server name
[Sun Jan 21 10:41:21.276195 2018] [ssl:warn] [pid 26748] AH01909: hxueh.net:443:0 server certificate does NOT include an ID which matches the server name
[Sun Jan 21 10:41:21.276370 2018] [wsgi:warn] [pid 26748] mod_wsgi: Compiled for Python/3.5.1+.
[Sun Jan 21 10:41:21.276378 2018] [wsgi:warn] [pid 26748] mod_wsgi: Runtime using Python/3.5.2.
[Sun Jan 21 10:41:21.278888 2018] [mpm_prefork:notice] [pid 26748] AH00163: Apache/2.4.18 (Ubuntu) OpenSSL/1.0.2g mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Sun Jan 21 10:41:21.278910 2018] [core:notice] [pid 26748] AH00094: Command line: '/usr/sbin/apache2'
[Sun Jan 21 10:44:02.826408 2018] [wsgi:error] [pid 26751] [client xxx.xxx.xxx.xxx:xxx] No WSGI daemon process called 'finance' has been configured: /var/www/html/hxueh.net/finance/finance.wsgi

更新:问题已解决。

我重写结构并将wsgi文件放入项目中。

|--------Finance
|----------------static
|----------------templates
|----------------venv
|----------------application.py
|----------------finance.wsgi

我也重写了Apache 2文件。我禁用了WSGIProcessGroup,因为我不需要它。

<VirtualHost *:80>
        ServerName finance.hxueh.net
        ServerAdmin [email protected]
        WSGIScriptAlias / /var/www/html/hxueh.net/Finance/finance.wsgi
        <Directory /var/www/html/hxueh.net/Finance/>
                Order allow,deny
                Allow from all
        </Directory>
        <Directory /var/www/html/hxueh.net/Finance>
                Order deny,allow
                Allow from all
        </Directory>
        Alias /static /var/www/html/hxueh.net/Finance/static
        <Directory /var/www/html/hxueh.net/Finance/static/>
                Order allow,deny
                Allow from all
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

确保在/etc/apache2/mods-available/mod.load中启用mod_wsgi。只需运行mod_wsgi-express module-config并将输出放入其中即可。然后运行sudo a2enmod wsgisudo service apache2 restart

我的finance.wsgi是:

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

from application import app as application

最后,感谢Graham Dumpleton帮助我部署了第一个Web应用程序。

格雷厄姆·邓普顿

你有:

WSGIProcessGroup finance

告诉mod_wsgi将请求发送到运行在守护进程组中但尚未配置守护进程组的WSGI应用程序。

WSGIScriptAlias指令前添加

WSGIDaemonProcess finance

另请阅读:

了解有关守护进程组的更多信息。

顺便说一句,mod_wsgi 4.3.0的版本很旧。您应该避免在Debian / Ubuntu上使用系统提供的用于mod_wsgi的软件包,因为它们通常已经过时,并且不受支持。建议您卸载系统软件包并使用pip安装方法自行从源代码安装。看到:

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在mod_wsgi中运行的烧瓶无法写入/ tmp

mod_wsgi 无法解析 WSGI 脚本文件 | 处理 WSGI 脚本时发生异常 | 无法导入“站点”模块

mod_wsgi不断重启flask应用

尝试使用mod_wsgi设置烧瓶

Django(mod_wsgi)处理WSGI脚本时发生异常

CentOs 7 无法安装 mod_wsgi

mod_wsgi无法连接WSGI守护进程

Flask中的静态文件-robot.txt,sitemap.xml(mod_wsgi)

在 mod_wsgi 部署的 Flask 应用程序中 Adafruit_MotorHAT 的权限被拒绝

让Flask使用Python3(Apache / mod_wsgi)

通过mod_wsgi在WebFaction上运行Flask-SocketIO

无法使用mod_wsgi确定apache中HTTP 500的原因

Django用mod_wsgi如何设置PYTHONHASHSEED env变量?

使用mod_wsgi用apache设置Django

使用mod_wsgi设置Django1.1.4

Django内部500错误:尝试设置mod_wsgi

Apache + mod_wsgi + flask应用程序:日志中出现“无法获取存储桶旅的请求”错误

无法在树莓派上的 Python3.5 下使用 apache2、mod_wsgi 导入flask_cors

在 Google Compute Engine 上为 Flask 配置 Apache WSGI(使用 mod_wsgi 的 Flask 导入错误)

无法在 Apache (mod_wsgi) 上部署官方 Django 教程

无法使用Apache + mod_wsgi远程访问Django应用

Apache 无法使用 mod_wsgi 作为 Windows 服务启动

pip install mod_wsgi,如何设置MOD_WSGI_APACHE_ROOTDIR环境?

Django MOD_WSGI设置?MOD_WSGI Apache2 403您无权访问此资源

mod_wsgi:处理WSGI脚本时发生异常(Django部署)

pip install mod_wsgi在virtualenv中失败

在Django mod_wsgi脚本中访问请求标头

在virtualenv中,Django的Apache mod_wsgi错误

卡在mod_wsgi上