以下是我的环境:
http://server:8107/api
上通过WSGI(mod_wsgi)运行 /opt/wsgi/staticfiles/subdomain
http://server:3002/
我需要将所有这些在端口80上的虚拟主机下进行分组,如下所示:
以下是configuration的相关部分:
<VirtualHost *:80> ServerName subdomain.server ServerAlias subdomain.server.local Alias /api/static/ /opt/wsgi/staticfiles/subdomain/ <Directory /opt/wsgi/staticfiles/subdomain/ > Order Allow,Deny Allow from All Options -Indexes IndexOptions Charset=UTF-8 </Directory> ProxyPass /api http://127.0.0.1:8107/api ProxyPassReverse /api http://127.0.0.1:8107/api ProxyPass / http://127.0.0.1:3002/ ProxyPassReverse / http://127.0.0.1:3002/ </VirtualHost>
现在,当我尝试访问一个静态资源(比如说/api/static/js/jquery.js
)时,我发现URL并不是由Alias指令首先parsing,而是传递给WSGI应用程序( /api
),然后显然会引发404错误。
重新sorting指令似乎没有任何影响。
我应该改变什么,以确保HTTPD将服务/api/static
之前呢?
*编辑*:我在CentOS 6.5发行版下运行Apache HTTPD 2.2.15
以下conf是你正在寻找的:
ProxyPass /api/static !
它告诉Apache在将代码路由到代理应用程序时不考虑这个path,因此可以使用其他types的访问(这里是您的Alias指令)进行处理。