你好瓶使用Apache和mod_wsgi的世界显示了在根目录的文件只 [英] Flask hello world using apache and mod_wsgi shows files in webroot only

查看:551
本文介绍了你好瓶使用Apache和mod_wsgi的世界显示了在根目录的文件只的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行从烧瓶网站上使用WSGI的Apache2基本hello.py。这里是我的code样子:

I'm attempting to run the basic hello.py from the flask site over apache2 using wsgi. Here is what my code looks like:

/var/www/flask_dev/hello.py

/var/www/flask_dev/hello.py

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

if __name__ == '__main__':
    app.run()

/var/www/flask_dev/start.wsgi

/var/www/flask_dev/start.wsgi

from hello import app as application

import sys
sys.stdout = sys.stderr

/etc/apache2/sites-available/flask_dev.conf

/etc/apache2/sites-available/flask_dev.conf

#Listen 80
ServerName example.com

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    #ServerName example.com

    WSGIDaemonProcess hello user=<myuser> group=<myusersgroup> threads=5 python-path=/var/www/flask_dev

    WSGIScriptAlias / /var/www/flask_dev/start.wsgi
    <Directory /var/www/flask_dev>
           WSGIProcessGroup hello
           WSGIApplicationGroup %{GLOBAL}
           Order deny,allow
           Allow from all
    </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

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

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

/ etc / hosts中

/etc/hosts

127.0.0.1    example.com

在我运行须藤a2ensite flask_dev 须藤服务的Apache2重新加载(或重新启动),将 www.example.com 只是给在Web根目录中的文件。 ~~我检查错误日志,它看起来像mod_wsgi的和mod_python正在启动。有谁知道我错过了什么吗?~~

After I run sudo a2ensite flask_dev and sudo service apache2 reload (or restart), going to www.example.com just gives the files in the webroot. ~~I've checked the error log and it looks like mod_wsgi and mod_python are starting up. Does anyone know what else I'm missing?~~

修改1
我现在能看到从错误日志消息,它看起来像我受到<一href=\"https://bugs.launchpad.net/ubuntu/+source/libapache2-mod-python/+bug/1073147\">https://bugs.launchpad.net/ubuntu/+source/libapache2-mod-python/+bug/1073147在Ubuntu 12.04。

Edit 1 I'm now able to see messages from the error log, and it looks like I am affected by https://bugs.launchpad.net/ubuntu/+source/libapache2-mod-python/+bug/1073147 on Ubuntu 12.04.

我稍后会尝试重新编译到正确的Python版本,看它是否修复该错误。现在,当出现这个错误,我仍然看到列出的文件,当我访问example.com。

I will try recompiling later to the correct Python version to see if it fixes the error. For now, while this error occurs, I'm still seeing the files listed when I visit example.com.

error.log中

error.log

[Mon Jan 13 11:28:06 2014] [notice] caught SIGTERM, shutting down
[Mon Jan 13 11:28:07 2014] [error] python_init: Python version mismatch, expected '2.7.2+', found '2.7.3'.
[Mon Jan 13 11:28:07 2014] [error] python_init: Python executable found '/usr/bin/python'.
[Mon Jan 13 11:28:07 2014] [error] python_init: Python path being used '/usr/lib/python2.7/:/usr/lib/python2.7/plat-linux2:/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/lib-old:/usr/lib/python2.7/lib-dynload'.
[Mon Jan 13 11:28:07 2014] [notice] mod_python: Creating 8 session mutexes based on 6 max processes and 25 max threads.
[Mon Jan 13 11:28:07 2014] [notice] mod_python: using mutex_directory /tmp 
[Mon Jan 13 11:28:07 2014] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Mon Jan 13 11:28:07 2014] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Mon Jan 13 11:28:07 2014] [notice] Apache/2.2.22 (Ubuntu) mod_python/3.3.1 Python/2.7.3 mod_wsgi/3.3 configured -- resuming normal operations

编辑2 更新到13.04解决了版本信息。现在,当我去example.com我得到一个403 Forbidden错误。当我的尾巴error.log中我看到的:

Edit 2 Updating to 13.04 has solved the version info. Now when I go to example.com I get a 403 forbidden error. When I tail the error.log I see:

[Mon Jan 13 21:03:41.464815 2014] [:error] [pid 10999:tid 3014634304] [client 127.0.0.1:35067] Attempt to invoke directory as WSGI application: /var/www/flask_dev/

我已经尝试添加 AddHandler的CGI脚本PY 我flask_dev.conf,但这似乎并没有任何工作。

I've tried adding AddHandler cgi-script py to my flask_dev.conf, but that doesn't seem to work either.

有没有人得到了这样那样的错误了WSGI应用程序,并知道这是一个解决办法呢?

Has anyone gotten this kind of error with a WSGI application before and know of a workaround for this?

先谢谢了。

修改3
所有的源$ C ​​$ C现在的工作。

Edit 3 All source code works now

推荐答案

在/var/www/flask_dev/hello.wsgi你应该导入应用程序没有屁股。
其次,你不应该使用的DocumentRoot来存储你的脚本。 DocumentRoot的是用于存储静态文件,所以它肯定会列出它们为文件,永远不会运行它们作为脚本。

in /var/www/flask_dev/hello.wsgi you should be importing app not ass. Second you should not be using DocumentRoot to store your scripts. DocumentRoot is for storing static files and so it will certainly list them as files and never run them as script.

尝试使用

    WSGIScriptAlias / /var/www/flask_dev/hello.wsgi
    <Directory "/var/www/flask_dev">
       WSGIProcessGroup hello
       WSGIApplicationGroup %{GLOBAL}
       Order deny,allow
       Allow from all
    </Directory>

页面。

这篇关于你好瓶使用Apache和mod_wsgi的世界显示了在根目录的文件只的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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