我正试图使用wsgi从apache2上的flask网站运行基本的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
from hello import app as application import sys sys.stdout = sys.stderr
/etc/apache2/sites-available/flask_dev.conf
如何在Apache和mod_wsgi中使用Flask路由?
Flask-Admin页面在生产中不可访问
如何防止使用Nginx的auth_request指令和烧瓶应用程序看似随机的重新authentication提示?
烧瓶Gunicorn应用程序不能得到__name__等于'__main__'
Dockerizing Nginx和Flask
#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,eg #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文件
127.0.0.1 example.com
在运行sudo a2ensite flask_dev和sudo service apache2 reload (or restart) ,转到www.example.com只是给webroot中的文件。 ~~我检查了错误日志,看起来像mod_wsgi和mod_python正在启动。 有谁知道我还错过了什么?
编辑1我现在可以看到来自错误日志的消息,它看起来像受到Ubuntu上的https://bugs.launchpad.net/ubuntu/+source/libapache2-mod-python/+bug/1073147的影响12.04。
我将稍后尝试重新编译为正确的Python版本,以查看是否修复了错误。 目前,在发生此错误时,我仍然在浏览example.com时看到列出的文件。
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禁止的错误。 当我尾巴的error.log我看到:
[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-script py添加到我的flask_dev.conf中,但是这似乎也不起作用。
有没有人得到这种Wsgi应用程序之前的错误,并知道这个解决方法?
提前致谢。
编辑3所有的源代码现在工作
使用Gunicorn + Nginx + Flask有什么好处?
如何弥补JavaScript中的Nginx的URL重写?
Nginx,uWsgi,Flask应用程序不显示更改,直到服务器重新启动
在/var/www/flask_dev/hello.wsgi你应该导入应用程序不屁股。 其次,您不应该使用DocumentRoot来存储脚本。 DocumentRoot用于存储静态文件,所以它肯定会列出它们作为文件,而不是将它们作为脚本运行。
尝试使用
WsgiScriptAlias / /var/www/flask_dev/hello.wsgi <Directory "/var/www/flask_dev"> WsgiProcessGroup hello WsgiApplicationGroup %{GLOBAL} Order deny,allow Allow from all </Directory>
检查这个页面。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。