[ACCEPTED]-ProxyPass, ProxyReverse vs AJP-proxypass

Accepted answer
Score: 23

Do it like this:

in the apache config:

<Location /foo>
  ProxyPass ajp://localhost:8009/foo
  ProxyPassReverse ajp://localhost:8009/foo

And 7 then in your server.xml:

<Connector port="8009" 
           enableLookups="false" secure="true" URIEncoding="UTF-8"
           protocol="AJP/1.3" />

That should pass 6 everything through. The AJP protocol passes 5 the info, but http: doesn't.

You may not 4 want secure="true", I use that because SSL 3 is handled at the apache layer and I need 2 tomcat to know that the connection should 1 be considered a secure one.

Score: 5

You can read the X-Forwarded-For in the 16 request header.

From the Apache mod_proxy documentation:

When acting in 15 a reverse-proxy mode (using the ProxyPass 14 directive, for example), mod_proxy_http 13 adds several request headers in order to 12 pass information to the origin server. These 11 headers are:

  • X-Forwarded-For: The IP address of the client.
  • X-Forwarded-Host: The original host requested by the client in the Host HTTP request header.
  • X-Forwarded-Server: The hostname of the proxy server.

Be careful when using these 10 headers on the origin server, since they 9 will contain more than one (comma-separated) value 8 if the original request already contained 7 one of these headers. For example, you can 6 use %{X-Forwarded-For}i in the log format 5 string of the origin server to log the original 4 clients IP address, but you may get more 3 than one address if the request passes through 2 several proxies.

In your servlet, you would 1 have:

doGet(HttpServletRequest request, HttpServletResponse response){
Score: 1

this is very simple:


 ServerName www.server.com

 redirect / http://www.server.com/foo

 ProxyRequests off
 ProxyPass / ajp://localhost:8009/



More Related questions