Apache HTTPD:具有代理和目录别名的虚拟主机的URLparsing

以下是我的环境:

  • REST api (django),在端口http://server:8107/api上通过WSGI(mod_wsgi)运行
  • API网站的静态文件 (我有一些pipe理页面),在一个目录中,说/opt/wsgi/staticfiles/subdomain
  • 运行在pm2 / nodejs上的Web应用程序 (expressjs)在http://server:3002/

我需要将所有这些在端口80上的虚拟主机下进行分组,如下所示:

  • http://subdomain.server/api :其余的API
  • http://subdomain.server/api/static :API网站所需的静态文件
  • http://subdomain.server/ :web应用程序

以下是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指令)进行处理。