使用Flask和wsgi进行Apache设置 [英] Apache set-up with Flask and wsgi

查看:74
本文介绍了使用Flask和wsgi进行Apache设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Flask和python构建的小型Web应用程序.使用我用于开发一切的内部服务器,一切运行正常.但是现在我想使用apache来开始使用它.但这是行不通的.请记住,我以前从未使用过Apache或基于Web的东西.

我以本指南为起点: http://flask.pocoo.org/docs/deploying/mod_wsgi/

现在我有我的应用程序,该应用程序位于名为"/rg/server.py"的文件中,如下所示:

app=Flask(__name__)
# all app routes...

if __name__ == '__main__':
    app.run(
        debug=True,
        host="127.0.0.1",
        port=80
    )

比我有一个wsgi文件为"/rg/wsgi/minerva.wsgi"

import sys
sys.path.insert(0, /rg)
from server import app as minerva

最后,我在"etc/apach2/sites-available/minerva.com"中有一个apache配置文件:

<VirtualHost *>
    ServerName minerva.test

    WSGIDaemonProcess minerva threads=10
    WSGIScriptAlias / /rg/wsgi/minerva.wsgi

    <Directory /rg>
    WSGIProcessGroup minerva
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all
    </Directory>

</VirtualHost>

然后,我使用成功的a2ensite minerva.com更新了apache.然后我说服了Apache,没有任何错误.但是我不能以任何方式访问minerva.test ...

如果我输入apache2ctl -S,它会列出minerva.test

我不知道出了什么问题...

系统信息: 操作系统:Debian 64bit python 2.7

解决方案

对于mod_wsgi,WSGI应用程序入口点必须称为"application".你有:

from server import app as minerva

应该是:

from server import app as application

您甚至还没走那么远,否则一行:

sys.path.insert(0, /rg)

会给出语法错误.

再往前走,而不是:

<VirtualHost *>

您应该拥有:

<VirtualHost *:80>

最后,如果'minerva.test'实际上不是可解析的主机,那么您将无所适从.

因此,使用在浏览器中使用的实际URL填写您的问题,并指出本地主机文件中是否甚至列出了"minerva.test".

I have a small web application that I have built using Flask and python. With the internal server that I used for developing everything runs fine. However now I want to use apache to start using it. But it doesn`t work. Keep in mind that I have never worked with apache or web based stuff before.

I used this guide as my starting point: http://flask.pocoo.org/docs/deploying/mod_wsgi/

right now I have my application which is in the file called "/rg/server.py" and looks like this:

app=Flask(__name__)
# all app routes...

if __name__ == '__main__':
    app.run(
        debug=True,
        host="127.0.0.1",
        port=80
    )

than I have a wsgi file as "/rg/wsgi/minerva.wsgi"

import sys
sys.path.insert(0, /rg)
from server import app as minerva

and finally I have an apache config file in "etc/apach2/sites-available/minerva.com":

<VirtualHost *>
    ServerName minerva.test

    WSGIDaemonProcess minerva threads=10
    WSGIScriptAlias / /rg/wsgi/minerva.wsgi

    <Directory /rg>
    WSGIProcessGroup minerva
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all
    </Directory>

</VirtualHost>

Then I updated apache with a2ensite minerva.com which succeded. Then I releaded Apache and no errors. However I cannot acces minerva.test in any way...

If I type in apache2ctl -S it does list minerva.test

I have no idea what is going wrong...

system information: OS: debian 64bit python 2.7

解决方案

The WSGI application entry point must be called 'application' for mod_wsgi. You have:

from server import app as minerva

It should be:

from server import app as application

You aren't even getting that far though, else the line:

sys.path.insert(0, /rg)

would give a syntax error.

Going back further, instead of:

<VirtualHost *>

you should have:

<VirtualHost *:80>

and finally, if 'minerva.test' isn't actually a resolvable host, you will not get anywhere.

So fill out your question with the actual URL you are using in the browser and also indicate whether 'minerva.test' is even listed in local hosts file.

这篇关于使用Flask和wsgi进行Apache设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆