2

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.

Adriano P
  • 243
  • 3
  • 8

1 Answers1

1

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/"
Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129
  • Thanks for point out the ProxyPass "!", but it didn't work as expected inside (at least in Apache 2.4). I had to move the `ProxyPass` out of the Location directive to make it work. Note: you need to put `ProxyPass !` before the `ProxyPass http://..."`. Also, `Alias` can't be placed inside Location. – Adriano P May 28 '17 at 03:11
  • Both have examples inside `` in the official documentation, but there's a limitation: "If the `Alias` directive is used within a `` or `` section the URL-path is omitted, and the file-path is interpreted using expression syntax. This syntax is available in Apache 2.4.19 and later." – Esa Jokinen May 28 '17 at 04:49
  • I improved my answer by adding both alternatives & full configuration. – Esa Jokinen May 28 '17 at 08:50
  • 1
    Despite what documentation states, this error is shown when I put alias (without the URL, just like in @Esa example) inside Location: `Alias not allowed here`. – Adriano P May 29 '17 at 04:27