1

N00b question. I have an URL

 http://myserver.com/game

and would like to call an internal resource

 http://localhost:5732/

I tried:

AllowCONNECT 5732
ProxyPass /game/ http://localhost:5732/ nocanon
ProxyPassReverse /game/ http://localhost:5732/

but the HTML coming back contained links that didn't get /game/ prepended and JS and CSS broke. So I tried:

 RewriteEngine On
 RewriteRule ^/game(.*) http://localhost:5732$1

but that sends a redirect (which of course doesn't work) to the browser.

What do I get wrong? My goal is:

 http://myserver/game --> http://localhost:5732/ 

Help is greatly appreciated

2 Answers 2

3

If your Apache version is recent enough (2.4+), you can try mod_proxy_html

ProxyPass /game http://localhost:5732 nocanon
ProxyPassReverse /game http://localhost:5732
<Location /game/>
    ProxyHTMLEnable On
    ProxyHTMLURLMap / /game/
</Location>

For older versions of apache, you can try with mod_substitute. However, this requires you to manually write your regexes. This could be a starting point:

ProxyPass /game http://localhost:5732 nocanon
ProxyPassReverse /game http://localhost:5732
<Location /game/>
    SetOutputFilter SUBSTITUTE
    Substitute s|href='/|href='/game/|nq
    Substitute s|src='/|src='/game/|nq
</Location>

Of course, the exact configuration will depend on what output you currently get from your game server.

4
  • For the moment I'm stuck with 2.2, so I'll give mod_substitude a try. I guess I'll also need Substitude s|href='http : // localhost/|href='http : // myserver.com/game|nq
    – stwissel
    Aug 26, 2012 at 12:17
  • 2 Questions: Will the ' catch both ' and " and what does the |nq do?
    – stwissel
    Aug 26, 2012 at 12:18
  • The |nq are modifiers to change the behavior of the Substitute command, you can check out the different modifiers in the documentation. In short, the 'q' modifier increases performance (but it may break more complex configurations, for this kind of simple substitutions you should be fine though). The 'n' modifier disables regex behavior, which allows you to simplify the used syntax a bunch and also improves performance.
    – brain99
    Aug 26, 2012 at 12:27
  • And no, the ' only matches exactly that character. So if you have some occurrences with ' and some with ", you will need two Substitute rules. Note that if you have spaces in your rules, you need to enclose them in quotes as well. You can also escape quotes within your rules. For example, suppose you need to modify a javascript: window.location.href = "/";, then your Substitute rule could look like Substitute "s|window.location.href = \"/\";|window.location.href = '/game/';|nq".
    – brain99
    Aug 26, 2012 at 12:32
2

The first version you did, with ProxyPass and ProxyPassReverse, is the most common way to do what you want. The problem is that whatever it is you've got running on localhost:5732 is the thing that creates the HTML that will be sent back - and it doesn't know that it's not called localhost:5732. Your proxypass doesn't change the pages that are passed through, it so if your game contains all the wrong links, that's what you'll see.

So, to make this work, you need to reconfigure your game thingy so it knows to present its links etc as your.server/game instead of localhost.5732.

1
  • Hi Jenny, what you describe is exactly what happened. I got the HTML back but it contained all relative links (e.g. stylesheets) based on / instead of /game/
    – stwissel
    Aug 26, 2012 at 12:12

You must log in to answer this question.

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