3

I have a few servlets listening on internal ports which are not accessible from outside. I use Apache's ProxyPass and ProxyPassReverse directives to serve them securely from port 443:

ProxyPass         /media http://localhost:9002/
ProxyPassReverse  /media http://localhost:9002/

This works fine - https://example.com/media is served from http://localhost:9002/.

The problem happens when the URL has a varying part. For example:

https://example.com/image/IMAGE_NAME_1 should be served from http://localhost:9002/image/IMAGE_NAME_1.

And https://example.com/image/IMAGE_NAME_2 should be served from http://localhost:9002/image/IMAGE_NAME_1.

I've tried some variations, including:

RewriteEngine  on
RewriteRule   ^/image/(.*)$  http://localhost:9002/image/$1 [L,PT]
ProxyPass         /image/ http://localhost:9002/image
ProxyPassReverse  /image/ http://localhost:9002/image

But this configuration results in Bad Request in the browser and

Invalid URI in request GET /image/1 HTTP/1.1

In the logs.

How do I proxy internal servlets where the URL has a varying part?

Adam Matan
  • 13,194
  • 19
  • 55
  • 75

1 Answers1

14

You use ProxyPassMatch instead:

ProxyPassMatch    ^/media http://localhost:9002/(.*)
ProxyPassReverse  ^/media http://localhost:9002/(.*)

Find further details in the Apache online documentation.

dawud
  • 15,096
  • 3
  • 42
  • 61