在Linux中使用apache和mod_wsgi配置Python flask应用程序 [英] Configure Python flask application with apache and mod_wsgi in linux

查看:61
本文介绍了在Linux中使用apache和mod_wsgi配置Python flask应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序帐户下有一个linux apache 2.4.12和mod_wsgi 4.5.2(安装到apache中的mod_wsgi.so).Apache在应用程序帐户下的端口8050下运行.通过此链接可以测试mod_wsgi的工作情况: http://mytest.mydomain.com:8050/myapp .它显示"Hello World",因此表明我的mod_wsgi安装正在工作.接下来,我尝试查看是否可以使烧瓶应用程序正常工作.

I have a linux apache 2.4.12 and mod_wsgi 4.5.2 (mod_wsgi.so installed into apache) under application account. Apache runs under port 8050 under application account. Following this link to test mod_wsgi working: http://modwsgi.readthedocs.org/en/develop/user-guides/quick-configuration-guide.html#wsgi-application-script-file and I entered my URL: http://mytest.mydomain.com:8050/myapp. It displayed "Hello World", so it indicated my mod_wsgi installation working. Next I tried to see if I can make flask application work.

我在/home/myuserId/wsgi下创建了简单的hello.py文件:

I created the simple hello.py file under /home/myuserId/wsgi:

from flask import Flask
app = Flask(__name__)

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

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

然后我创建了一个简单的wsgi文件,如下所示:

then I created a simple wsgi file as:

import sys, os
sys.path.insert(0, "/home/myuserId/wsgi")

from hello import app as application

然后,我遵循了其他建议,包括此 http://flask.pocoo.org/docs/0.10/deploying/mod_wsgi/,将我的apache http.conf文件与virtualhost配置为:

then I followed others suggestions including this http://flask.pocoo.org/docs/0.10/deploying/mod_wsgi/ to configure my apache http.conf file with virtualhost as:

<VirtualHost *:8050>

  # ServerName www.example.com

  WSGIDaemonProcess hello user=appuser group=appuser threads=5
  WSGIScriptAlias / /home/myuserId/wsgi/hello.wsgi

 <Directory /home/myuserId/wsgi>
    WSGIProcessGroup hello
    WSGIApplicationGroup %{GLOBAL}
    Require all granted
    Options +ExecCGI
    AddHandler wsgi-script .wsgi
 </Directory>
</VirtualHost>

我保存了httpd.conf文件并重新启动了Apache w/o错误.当我在Chrome中输入网址时: http://mytest.mydomain.com:8050/hello http://mytest.mydomain.com:8050/hello_world ,出现此错误:

I saved the httpd.conf file and restarted the apache w/o error. When I entered the URL in chrome: http://mytest.mydomain.com:8050/hello or http://mytest.mydomain.com:8050/hello_world, I got this error:

**Not Found**

The requested URL /hello was not found on this server.
Apache/2.4.12 (Unix) mod_wsgi/4.5.2 Python/2.7.9 Server at mytest.mydomain.com port 8050. 

我的问题是:

  1. 我的配置错误吗?
  2. 上述hello flask应用程序使用什么正确的URL?
  3. 尝试 WSGIScriptAlias/hello/home/myuserId/wsgi/hello.wsgi 挂载hello应用程序,但未找到.
  4. 对于flask应用程序,为什么conf文件必须在VirtualHost中将应用程序进行配置?
  1. is my configuration wrong?
  2. what is the right URL for the above hello flask application to use?
  3. tried WSGIScriptAlias /hello /home/myuserId/wsgi/hello.wsgi to mount hello application but not found either.
  4. for flask app, why does conf file have to conf the app in VirtualHost?

推荐答案

您没有使用主机名指定ServerName指令.结果,它将不匹配该VirtualHost,而是回退到在Apache配置文件中找到的第一个VirtualHost.

You aren't specifying ServerName directive with host name. As a result it will not match that VirtualHost and will instead fallback to whatever the first VirtualHost was that it found in the Apache configuration files.

这篇关于在Linux中使用apache和mod_wsgi配置Python flask应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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