I currently have a Tomcat + Apache HTTP server setting to serve my Java servlet:
ProxyPass /myservice http://localhost:8080/myservice
ProxyPassRerverse /myservice http://localhost:8080/myservice
This is all fine except that myservice
needs to know the client IP address, which always turns out to be 127.0.0.1 due to the proxy. Is there a solution to get the real IP address? Is AJP an option?
doGet(HttpServletRequest request, HttpServletResponse response){
request.getRemoteAddr()
}
A traditional forward proxy server allows multiple clients to route traffic to an external network. For instance, a business may have a proxy that routes and filters employee traffic to the public Internet. A reverse proxy, on the other hand, routes traffic on behalf of multiple servers.
HTTP connectors can also be used as part of a load balancing scheme, in conjunction with an HTTP load balancer that supports session stickiness, such as mod_proxy. However, as AJP tends to handle proxying better than HTTP, this usage is not common.
The ProxyPassReverse is used to change the headers sent to Apache from a proxied app server, before Apache sends it to the browser.
Apache JServ Protocol (AJP) is used for communication between Tomcat and Apache web server. This protocol is binary and is enabled by default. Anytime the web server is started, AJP protocol is started on port 8009. It is primarily used as a reverse proxy to communicate with application servers.
Do it like this:
in the apache config:
<Location /foo>
ProxyPass ajp://localhost:8009/foo
ProxyPassReverse ajp://localhost:8009/foo
</Location>
And then in your server.xml:
<Connector port="8009"
enableLookups="false" secure="true" URIEncoding="UTF-8"
tomcatAuthentication="false"
protocol="AJP/1.3" />
That should pass everything through. The AJP protocol passes the info, but http: doesn't.
You may not want secure="true", I use that because SSL is handled at the apache layer and I need tomcat to know that the connection should be considered a secure one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With