大网数据广告活动
服务器运维问答

Apache HTTPD: URL resolution for a virtual host with proxies and directory alias

· 52CE 我爱测

Here's what my environment looks like: REST api (django), running over WSGI (mod_wsgi) on port http://server:8107/api static files for the API site (i have some admin pages), in a directory, say /opt/wsgi/staticfiles/subdomain We…

问题原文

原帖链接 · Olivier H · CC BY-SA 3.0

Here's what my environment looks like:

  • REST api (django), running over WSGI (mod_wsgi) on port http://server:8107/api
  • static files for the API site (i have some admin pages), in a directory, say /opt/wsgi/staticfiles/subdomain
  • Web application (expressjs), running over pm2/nodejs, on http://server:3002/

I need to group all this under a virtualhost on port 80 as follows:

Here is the relevant part of the 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>

Now, when I try to access a static resource (let's say for example /api/static/js/jquery.js) i find that the url is not resolved first by the Alias directive, but rather passed to the WSGI app (/api), which then obviously fires a 404 error.

Re-ordering the directives does not seem to have any effect.

What should I change to ensure HTTPD will serve /api/static before anything else?

*EDIT*: I run Apache HTTPD 2.2.15 under a CentOS 6.5 distro

已采纳解答

原帖链接 · Guillaume Fenollar · CC BY-SA 3.0

The following conf is what you are looking for :

ProxyPass /api/static !

It tells Apache to not take this path into account when routing stuff to your proxied application, so it can be dealt with other kind of access (here your Alias directive).

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-08-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。