【发布时间】:2016-08-12 11:52:49
【问题描述】:
我在应用程序帐户下有一个 linux apache 2.4.12 和 mod_wsgi 4.5.2(mod_wsgi.so 安装到 apache)。 Apache 在应用程序帐户下的 8050 端口下运行。按照此链接测试 mod_wsgi 工作:http://modwsgi.readthedocs.org/en/develop/user-guides/quick-configuration-guide.html#wsgi-application-script-file,我输入了我的 URL:http://mytest.mydomain.com:8050/myapp。它显示“Hello World”,所以它表明我的 mod_wsgi 安装工作正常。接下来,我尝试查看是否可以使烧瓶应用程序正常工作。
我在 /home/myuserId/wsgi 下创建了简单的 hello.py 文件:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run()
然后我创建了一个简单的 wsgi 文件:
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 配置为:
<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 没有错误。当我在 chrome 中输入 URL:http://mytest.mydomain.com:8050/hello 或 http://mytest.mydomain.com:8050/hello_world 时,我得到了这个错误:
**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.
我的问题是:
- 是我的配置错误吗?
- 上述 hello flask 应用程序使用的正确 URL 是什么?
- 尝试
WSGIScriptAlias /hello /home/myuserId/wsgi/hello.wsgi挂载hello 应用程序,但也未找到。 - 对于flask app,为什么conf文件一定要在VirtualHost中配置app?
【问题讨论】:
标签: python apache flask mod-wsgi