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?

4
  • 1
    I only see URLs, no parameters. Feb 23, 2014 at 20:29
  • IMAGE_NAME is a parameter, because it varies between calls. Am I using the term incorrectly?
    – Adam Matan
    Feb 23, 2014 at 20:31
  • 1
    Yes, it appears so. There's no query string on any of these URLs, and that's where one would pass parameters. Feb 23, 2014 at 20:31
  • Of course, my bad. Parameters in URL context has that meaning. Regex matching would be a better description. Rewriting my answer.
    – Adam Matan
    Feb 23, 2014 at 20:43

1 Answer 1

14

You use ProxyPassMatch instead:

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

Find further details in the Apache online documentation.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .