0

What is the simplest way to configure apache 2.2 to listen on, say, 20 different ports and then proxy those requests to the same ports on another server? For example, a request to http://myserver.com:1000/ should be proxy-forwarded to http://otherserver.com:1000/, a request to http://myserver.com:1001/ should be proxy-forwarded to http://otherserver.com:1001/, and so on, for ports 1000 through 1019.

Getting my server to listen on 20 different ports is easily done with 20 Listen directives. The trouble is the proxy directives. The mod_proxy module's ProxyPass directive doesn't seem to have a place for any reference to the port number. I can make 20 different VirtualHost sections and put proxy directives in each one:

<VirtualHost *:1000>
  ProxyPass        / http://otherserver.com:1000/
  ProxyPassReverse / http://otherserver.com:1000/
</VirtualHost>

<VirtualHost *:1001>
  ProxyPass        / http://otherserver.com:1001/
  ProxyPassReverse / http://otherserver.com:1001/
</VirtualHost>

<VirtualHost *:1002>
  ProxyPass        / http://otherserver.com:1002/
  ProxyPassReverse / http://otherserver.com:1002/
</VirtualHost>

...

but that seems extremely tedious. Though I can generate all those blocks programmatically from a template, I have to believe there's a better way, maybe with a single mod_rewrite rule or something? Suggestions?

John Siracusa
  • 738
  • 7
  • 12
  • 1
    The ``s are tedious, but the `Listen`s weren't? I don't think there's gonna be any 'smooth' way to do this with Apache, unfortunately.. it's not really built for bulk port listeners. – Shane Madden Apr 14 '11 at 21:05
  • The `Listen`s were one line each, vs. at least 4 lines for the VirtualHost sections. I was looking for a one-liner like `RewriteRule (.*) http://otherserver.com:%{REQUEST_PORT}$1` or similar (but one that actually works :) If it's really not possible to do this in significantly fewer lines, then type that up as an answer and I'll accept it after I've given up hope of better answers :) – John Siracusa Apr 15 '11 at 00:10

2 Answers2

1

You'd be better served by using "rinetd", which is a TCP connection forwarder.

This is introduced & documented here:

-1

Make a script to write your config.

Espennilsen
  • 454
  • 3
  • 8
  • Like I said, I can generate the config programmatically (and I am actually doing so with a Puppet template). I'm just wondering if there's a simpler solution. – John Siracusa Apr 15 '11 at 00:11