Apache httpd-vhosts中的flask url路径

时间:2015-09-01 05:59:30

标签: apache flask path mod-wsgi

使用flask和mod_wsgi。

下面的Apache v2.4 httpd-vhost.conf:

<VirtualHost *:80>
    WSGIScriptAlias /admin /home/service/admin
    WSGIDaemonProcess admin user=operators processes=10 threads=5 

    WSGIApplicationGroup %{RESOURCE}

   <Directory /home/service/admin>
      WSGIProcessGroup admin
      Require all granted
    </Directory>

</VirtualHost>

我将url-path设置为/admin

html访问/api/store/list中的Ajax代码:

function getStoreList(){
    $.ajax({
        url:'/api/store/list',
        type:'POST' 
    });
}

如何访问/ admin / api / store / list而不修改url(/ api / store / list =&gt; / admin / api / store / list)?

在Apache中使用mod_rewrite? Flask中的其他东西?

1 个答案:

答案 0 :(得分:2)

The Javascript should really be using the full URL path including mount point. If you can't handle that, then why mount your WSGI application at a sub URL in the first place?

If for some reason you cannot make the code use the correct thing, try adding in addition to what you have:

WSGIScriptAlias /api/ /home/service/admin/api/

Yes the '/api/' is being added to the end of the path to the WSGI script file as last argument. That is needed so code thinks it is still mounted at root of web site and thus URL mapping sees full '/api/store/list'.