2013-07-02 10 views
0

我可以成功運行Flask jQuery example(在Flask's "AJAX with jQuery"頁的底部附近提到)。它運行在燒瓶開發服務器上,可在http://localhost:5000上訪問。在Apache代理下運行Flask jQuery示例

如何代理頁面,以便我可以訪問http://localhost/jqueryexample下的同一個應用程序?

我將此添加到我的Apache VirtualHost條目,以爲它會做的伎倆:

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

但新的URL給人的404錯誤:

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

我怎樣才能獲得的例子運行正確在「規範URL」下(不確定這是否是正確的術語)?或者,如何更改應用程序或Apache配置以獲得爲這兩個URL運行的jQuery示例?


BTW,這裏是你如何下載和運行問題的香草Flask jQuery example

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

回答

0

好吧,尋找到這進一步後,我想我回答我自己的問題:

顯然,而不是運行燒瓶開發服務器,並試圖代理它通過Apache httpd的,這是最好的應用程序直接部署到Apache使用mod_wsgi。有關如何做到這一點的準則已有詳細記錄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。瞧!

0

我沒有Apache的安裝在我的面前,但是如果你是進行代理應用不得你從

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

改變的index.html線6

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

謝謝,但沒有工作 - 沒有錯誤,但它不運行'_add_numbers'服務。另外,現在'http:// localhost:5000'給出了404錯誤。 –