如何设置.wsgi文件和apache配置以部署在Debain服务器上的Large Flask应用程序上?

时间:2016-04-08 07:13:40

标签: flask debian apache2 mod-wsgi wsgi

我根据Miguel Grinberg的Flask Web开发手册中的Large Application Structure创建了一个Flask应用程序。我已经按照how-to-deploy-a-flask-application-on-an-ubuntu-vps中的教程进行操作,并设法在我的服务器上部署单个文件Flask应用程序。我必须对我的.wsgi文件和apache配置实施哪些更改/修改才能托管大型结构化应用程序?

我的Apache2 .conf文件:

<VirtualHost *:80>
        ServerName devrupt.com
        ServerAdmin lui@devrupt.com
        WSGIScriptAlias / /var/www/Devrupt/devrupt.wsgi
        <Directory /var/www/Devrupt/Devrupt/>
                Order allow,deny
                Allow from all
        </Directory>
        Alias /static /var/www/Devrupt/Devrupt/static
        <Directory /var/www/Devrupt/Devrupt/static/>
                Order allow,deny
                Allow from all
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

我的.wsgi文件:

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/Devrupt/")

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

1 个答案:

答案 0 :(得分:0)

尝试添加:

DocumentRoot /path/to/rootdir
WSGIDaemonProcess <projectname> user=flask group=www-data threads=2 home=/path/to/rootdir/project
WSGIProcessGroup <projectname>
WSGIScriptAlias / /path/to/rootdir/project/flask.wsgi

如果您正在使用virtualenv,请将此添加到.wsgi文件中:

activate_this = '/path/to/rootdir/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))