【问题标题】:How to correctly deploy a flask application with mod_wsgi on Apache2.2如何在 Apache2.2 上正确部署带有 mod_wsgi 的烧瓶应用程序
【发布时间】:2014-06-30 07:20:44
【问题描述】:

我一直在尝试在 Ubuntu Web 服务器上部署我的应用程序,但收效甚微。我定义的虚拟主机文件是:

    #WSGIRestrictStdout Off
    <VirtualHost *:80>
    ServerName demo.engineerinme.com
    WSGIDaemonProcess fedoracollege  user=engineer group=www-data threads=5
    WSGIScriptAlias / /home/engineer/fedora-college/fedora_college.wsgi
    <Directory /home/engineer/fedora-college/>
                    WSGIProcessGroup fedoracollege
                    WSGIApplicationGroup %{GLOBAL}
                    WSGIScriptReloading On
                    Options All ExecCGI Indexes FollowSymLinks
                    Order allow,deny
                    Allow from all

    </Directory>

    Alias /static /home/engineer/fedora-college/fedora_college/static
    <Directory /home/engineer/fedora-college/fedora_college/static/>
                    Order allow,deny
                    Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel debug
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>

我面临的问题是,静态内容工作正常,但烧瓶应用程序没有运行。像http://demo.engineerinme.com 一样显示未找到错误。但http://demo.engineerinme.com/static 有效。

部署的wsgi脚本是:

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/home/engineer/fedora-college/")

from fedora_college import app as application
application.secret_key = 'Add your secret key'

错误日志:

[Mon Jun 30 23:01:31 2014] [debug] mod_deflate.c(615): [client 59.177.114.30] Zlib: Compressed 233 to 180 : URL /
[Mon Jun 30 23:01:32 2014] [debug] mod_deflate.c(615): [client 59.177.114.30] Zlib: Compressed 233 to 180 : URL /
[Mon Jun 30 23:01:51 2014] [debug] mod_deflate.c(615): [client 59.177.114.30] Zlib: Compressed 233 to 180 : URL /

Access.log

        59.177.114.30 - - [30/Jun/2014:23:01:32 +0400] "GET / HTTP/1.1" 404 441 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"
        59.177.114.30 - - [30/Jun/2014:23:01:51 +0400] "GET / HTTP/1.1" 404 442 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"

应用程序的代码在这里:https://github.com/hammadhaleem/fedora-college/

对于可能的部署提供任何帮助将不胜感激。

谢谢

【问题讨论】:

  • 请同时包含 apache 错误日志
  • @PaoloCasciello ,我已经添加了日志文件的输出。
  • 不,我认为这不是强制性的。
  • @PaoloCasciello #已解决。谢谢:)

标签: python apache flask mod-wsgi


【解决方案1】:

我遇到了这个问题,同样的解决方案是在虚拟主机文件中。

有时 Apache 日志也会显示此错误:

[Mon Oct 17 15:24:24 2011] [error] [client 90.181.85.69] (13)Permission denied: mod_wsgi (pid=21805): Unable to connect to WSGI daemon process 'fedoracollege' on '/var/run/apache2/wsgi.16282.4.1.sock' after multiple attempts.

此问题已在此处正确解释。我刚刚重建了wsgi_mod。

https://serverfault.com/questions/322131/wsgi-says-permissions-denied-on-my-ubuntu-server-no-wsgisocketprefix-setting

另外,将虚拟主机文件重写为这种格式。 (去掉virtualhost和direcory标签)

Alias /static  /home/engineer/fedora-college/fedora_college/static
WSGIDaemonProcess fedoracollege user=engineer group=www-data threads=5
#WSGIDaemonProcess fedoracollege maximum-requests=1000 display-name=fedora-college processes=4 threads=4
WSGISocketPrefix /var/run/wsgi
WSGIRestrictStdout Off
WSGIRestrictSignal Off
WSGIPythonOptimize 1
WSGIScriptAlias /  /home/engineer/fedora-college/fedora_college.wsgi
<Location />
    WSGIProcessGroup fedoracollege
</Location>


ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined

另外,设置

application = True 

用于正确的错误报告。

希望这对某人有所帮助。 (别忘了点赞:P)

感谢您的所有帮助。

【讨论】:

  • 你很长一段时间都不需要 WSGIRestrictStdout 或 WSGIRestrictSignal 。 WSGIPythonOptimize 也没有真正为你买任何东西。你的意思可能不是'application = True'。
  • 奇怪,因为我没有看到与我突出显示的内容相关的页面的任何编辑。
猜你喜欢
  • 2012-08-03
  • 2018-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多