Retrieving the client source port in the HTTPD settings & # 8594; Tomcat

I have an httpd server configured to work with HTTPS connections and forward connections to Tomcat (via http or ajp) where requests are processed. One of the requirements that I have on the Tomcat server is to register the remote port number of each request. If I immediately got into Tomcat, retrieving the remote port number directly, and we are currently doing this using the getRemotePort()(HttpServletRequest) function .

However, since I am doing a reverse proxy (forwarding HTTPS requests via HTTP / AJP), a new connection will be created, and I always get a remote port (and a remote IP address) to connect from my httpd server to tomcat (unless I am using AJP. In this case, the IP address information of the remote server is arriving correctly).

I tried different configurations on httpd, for example:

ProxyPreserveHost On
ProxyPass / ajp://localhost:8009/

or

ProxyPreserveHost On
ProxyPass / http://localhost:8081/

I also played a little with RewriteRules, but couldn't get everything to work.

Reading httpd documentation, mod_proxy offers request header information for things like X-Forwarded-Host, X-Forwarded-Foretc. But there is no information about the source port.

I even found an error where, apparently, the attribute X-Forwarded-Portwas added to the header of the proxy request, but this code did not seem to do to the main line / branch.

, , ( ), HTTPD Tomcat?

+5
2

X-Forwarded-SourcePort mod_rewrite + mod_headers

RewriteEngine on
RewriteRule .* - [E=REMOTE_PORT:%{REMOTE_PORT},NE]
RequestHeader set X-Forwarded-SourcePort %{REMOTE_PORT}e

Apache , X-Forwarded-SourcePort .

+3

, mod_rewrite

RewriteRule Substitution,

In addition to plain text, the Substition string can include

    back-references ($N) to the RewriteRule pattern
    back-references (%N) to the last matched RewriteCond pattern
    server-variables as in rule condition test-strings (%{VARNAME})

REMOTE_PORT. URL- URL- Tomcat, .

http://url.to.tomcat/mycontext?remoteport=${REMOTE_PORT}

0

All Articles