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

Bypass Location with Alias in Apache2

· 52CE 我爱测

I'd like to know how to use Apache as a reverse proxy for a specific path and as local server for its sub-paths. For a specific location, I am using Apache as a reverse proxy ( https://my.server.com/my-tools ): <Location /my-tool…

问题原文

原帖链接 · Adriano P · CC BY-SA 3.0

I'd like to know how to use Apache as a reverse proxy for a specific path and as local server for its sub-paths.

For a specific location, I am using Apache as a reverse proxy (https://my.server.com/my-tools):

<Location /my-tools>
    Order allow,deny
    Allow from all
    ProxyPass http://10.1.1.11:3101/my-tools
    ProxyPassReverse http://10.1.1.11:3101/my-tools
</Location>

The thing is that for its assests I'd like to use the local server (https://my.server.com/my-tools/images/). I have tried adding Alias with no success:

Alias /my-tools/images/ /home/myself/public/images/
<Directory /home/myself/public/images/>
    Order allow,deny
    Allow from all
</Directory>

I tried also to add this, but it didn't work either:

<Location /my-tools/images/>
    SetHandler None
</Location>

It keeps redirecting to the remote server when I enter https://my.server.com/my-tools/images/myimage.png, for example.

已采纳解答

原帖链接 · Esa Jokinen · CC BY-SA 3.0

There's a direct example in the mod_proxy ProxyPass documentation:

The ! directive is useful in situations where you don't want to reverse-proxy a subdirectory, e.g.

<Location "/mirror/foo/">
    ProxyPass "http://backend.example.com/"
</Location>
<Location "/mirror/foo/i">
    ProxyPass "!"
</Location>

In your situation that would be:

<Location "/my-tools/images">
    ProxyPass "!"
    Alias "/home/myself/public/images"
</Location>
<Location "/my-tools/">
    ProxyPass http://10.1.1.11:3101/my-tools/
    ProxyPassReverse http://10.1.1.11:3101/my-tools/
</Location>

Or with alternative syntax:

ProxyPass "/my-tools/images" "!"
Alias "/my-tools/images" "/home/myself/public/images"
ProxyPass "/my-tools/" "http://10.1.1.11:3101/my-tools/"
ProxyPassReverse "/my-tools/" "http://10.1.1.11:3101/my-tools/"

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

资料来源与适用范围

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

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

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