[英]running Flask jQuery example under Apache proxy
我可以成功运行Flask jQuery示例 (在Flask的“带有jQuery的AJAX”页面的底部附近提到。)它在flask开发服务器上运行,可以从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”下正确运行(不确定这是否是正确的术语)? 或者,如何更改应用程序或Apache配置,以使这两个URL都运行此jQuery示例?
顺便说一句,这是您下载和运行有问题的香草Flask jQuery示例的方法:
git clone http://github.com/mitsuhiko/flask
cd flask/examples/jqueryexample/
python jqueryexample.py
好吧,在进一步研究之后,我想我回答了我自己的问题:
显然,与其运行烧瓶开发服务器并尝试通过Apache httpd代理它,不如最好使用mod_wsgi将应用程序直接部署到Apache。 有关如何执行此操作的指南已在此处详细记录。 实际上,对于生产而言,完全不建议使用dev服务器(请参阅此处) 。
至于部署jQuery Flask示例本身,这是您要做的(假设您的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
正在运行的应用程序。 瞧!
我前面没有安装Apache,但是如果您代理该应用程序,则不应该将index.html的第6行更改为
$.getJSON($SCRIPT_ROOT + '/_add_numbers', {
至
$.getJSON($SCRIPT_ROOT + '/jqueryexample/_add_numbers', {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.