2I have following configuration:
---443-> Load-Balancer-1 ---80> Apache-Proxy ---8080> Tomcat
---443-> Load-Balancer-2 ---81> Apache-Proxy ---8081> Tomcat
---443-> Load-Balancer-3 ---82> Apache-Proxy ---8082> Tomcat
There are several entries in the Apache server over different ports 80, 81, 81. There is a Tomcat listening port for every Apache port. Here is the simplified configuration:
<VirtualHost *:80 *:81 *:82>
RewriteRule ^/(.*) ://localhost:80<xx>/$1 [P,L]
</VirtualHost>
In the configuration above instead of <xx>
the physical apache port number must be used. In this case 80, 81 or 82.
I tried using %{SERVER_PORT}
, but it is never a physical port. If the UseCanonicalName Off
, it is the port of the load balancer (443 in my example). If the UseCanonicalName On
, it is one of ports configured in the Apache configuration. In my case it always was 82.
UseCanonicalPhysicalPort On|Off
directive was theoretically designed to solve this problem, but it seems not to be flexible enough for virtual host configuration.
http://httpd.apache.org/docs/current/mod/core.html#usecanonicalphysicalport
I tried to access CGI variable SERVER_PORT
as %{ENV:SERVER_PORT}
, but it did not exist.
I tried to workaround the problem using SetEnvIf
, but this directive has no access to the port number at all (why?).
Current working solution was creating three different virtual host and hardcode the port number, but I do not like it.