Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ProxyPass, ProxyReverse vs AJP

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()
}
like image 848
user121196 Avatar asked Jul 25 '09 02:07

user121196


People also ask

What is the difference between ProxyPass and ProxyPassReverse?

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.

Is AJP better than HTTP?

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.

What does ProxyPassReverse mean?

The ProxyPassReverse is used to change the headers sent to Apache from a proxied app server, before Apache sends it to the browser.

What is AJP used for?

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.


1 Answers

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.

like image 149
caskey Avatar answered Nov 03 '22 04:11

caskey