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?
You'd be better served by using "rinetd", which is a TCP connection forwarder.
This is introduced & documented here:
Make a script to write your config.