如何在Apache2.2上正确部署带有mod_wsgi的烧瓶应用程序

时间:2014-06-30 07:20:44

标签: python apache flask mod-wsgi

我一直在尝试在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/

任何有关可能部署的帮助都将受到高度赞赏。

谢谢

1 个答案:

答案 0 :(得分: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 

正确的错误报告。

希望这有助于某人。 (别忘了upvote:P)

感谢您的帮助。

相关问题