在Apache代理下运行Flask jQuery示例

时间:2013-07-02 20:57:53

标签: jquery python apache flask mod-proxy

我可以成功运行Flask jQuery example(在Flask's "AJAX with jQuery"页面底部附近提及。)它在烧瓶开发服务器上运行,可以在http://localhost:5000访问。

如何代理页面以便我可以访问http://localhost/jqueryexample下的同一个应用程序?

我将此添加到我的Apache VirtualHost条目中,认为它可以解决这个问题:

ProxyPass /jqueryexample http://localhost:5000/
ProxyPassReverse /jqueryexample http://localhost:5000/

但新网址出现404错误:

GET http://localhost/_add_numbers?a=6&b=2 404 (Not Found)

如何让示例在“规范URL”下正确运行(不确定这是否是正确的术语)?或者,如何更改app或Apache配置以便为这两个URL运行此jQuery示例?


BTW,以下是您如何下载和运行有问题的香草Flask jQuery example

git clone http://github.com/mitsuhiko/flask 
cd flask/examples/jqueryexample/ 
python jqueryexample.py

2 个答案:

答案 0 :(得分:1)

好的,在进一步研究之后,我想我回答了自己的问题:

显然,不是运行烧瓶开发服务器并尝试通过Apache httpd代理它,最好使用mod_wsgi将应用程序直接部署到Apache。有关如何执行此操作的指南已有详细记录here。实际上,对于生产,根本不建议使用开发服务器(参见here。)

至于部署jQuery Flask example本身,这就是你做的(假设你的DocumentRoot是/var/www/html):

# Get the example code.
git clone http://github.com/mitsuhiko/flask 
cd flask/examples/jqueryexample/

# Create WSGI file.
echo "\
import sys\
sys.path.insert(0, '/var/www/html/jqueryexample')\
from jqueryexample import app as application\
" > jqueryexample.wsgi

# Deploy to httpd.
sudo mkdir /var/www/html/jqueryexample
sudo cp -r * /var/www/html/jqueryexample/

现在将其添加到您的VirtualHost:

WSGIScriptAlias /jqueryexample /var/www/html/jqueryexample/jqueryexample.wsgi
<Location /var/www/html/jqueryexample>
    Allow from all
    Order allow,deny
</Location>

然后重启httpd。现在查看http://localhost/jqueryexample处正在运行的应用。瞧!

答案 1 :(得分:0)

我没有在我面前安装Apache,但如果您代理应用程序,则不应该更改index.html的第6行

$.getJSON($SCRIPT_ROOT + '/_add_numbers', {

$.getJSON($SCRIPT_ROOT + '/jqueryexample/_add_numbers', {