当前位置: 首页 > 知识库问答 >
问题:

无法解决烧瓶设置中的mod_wsgi异常

郎言
2023-03-14

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

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

我遵循了这里的指示。我的Linode服务器上有一个Flask应用程序,位于/var/www/html/hxueh。净额/财务。财务文件夹中有一个文件和一个文件夹。结构看起来像这样。

|--------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

金融。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 hxueh1996@gmail.com
        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 hxueh1996@gmail.com
        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中启用mod_wsgi。html" target="_blank">负载只需运行mod_wsgi-express module config,并将输出放入其中。然后运行sudo a2enmod wsgi和sudo服务apache2 restart。

我的财务。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

最后,感谢格雷厄姆·邓普尔顿帮助我部署我的第一个web应用程序。

共有1个答案

经福
2023-03-14

你有:

WSGIProcessGroup finance

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

在WSGIScriptAlias指令之前添加:

WSGIDaemonProcess finance

另请阅读:

  • http://modwsgi.readthedocs.io/en/develop/user-guides/configuration-guidelines.html#defining-process-groups

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

顺便说一句,mod_wsgi4.3.0版本非常旧。您应该避免在Debian/Ubuntu上使用系统提供的mod_wsgi包,因为它们通常已经过时且不受支持。建议您卸载系统包并使用pip安装方法自己从源代码安装。请参阅:

  • https://pypi.python.org/pypi/mod_wsgi
 类似资料:
  • 我正在尝试使用mod_wsgi在Ubuntu 16.04上通过apache安装flask应用程序。问题是wsgi脚本无法导入任何python模块。 我已经验证了wsgi脚本是可执行的,并用python独立运行了它。我还验证了我的flask应用程序可以自己运行,没有错误。我能够在我运行的任何其他python程序中导入所有模块。我还安装了带有pip和源代码的烧瓶。似乎什么都没用。 这是我的错误日志:

  • 我有一个基本的“hello world”烧瓶应用程序正在运行。 我在Ubuntu 14.04上,使用Apache 2.4。我安装了mod_wsgi。 我创建了一个~/web/piFlask/venv/来保存一个安装了flask的virtualenv创建的Python2。 但是,我希望我的flaskapp导入我编写的Python3. x模块。 我需要做什么才能做到这一点? 我试着创建一个

  • 我基本上使用了install命令“$pip install Flask”,当我试图运行一个程序时,它会说“找不到模块”Flask安装在“/usr/local/lib/python2.7/site包”中,但我认为pip的意义在于,我可以到处导入这些包。我试图在我的桌面上运行一个文件,甚至当我将Flask文件夹移动到桌面上时,它也不起作用。有什么建议吗?谢谢

  • 问题内容: 我遇到的烧瓶SQLAlchemy的一个问题,我可以设置对象的属性 place_collections ,但是当我想设置为对象属性 的地方 ,发生了错误: 如何设置联接搜索对象的属性,有人可以帮助我吗? 它们都是 “ flask_sqlalchemy.BaseQuery” 类。 模型 问题答案: 将返回您的对象集合。这类似于普通的香草SQLAlchemy。 但是,从SQLAlchemy

  • 任何人请建议如何摆脱已经运行的应用程序。我试过很多关于杀戮过程的东西,但没有一个是真的奏效的。

  • 谢谢你的回应。 向Joern问好