title: Does tomcat know that haproxy is a proxy server?
body: <p>I have a couple of questions in regards to HAProxy (1.5.2) and Tomcat (7.0.54). Both I am a newbie in.</p>
  
  <p>In Tomcat I have an application that on login (<em>https://my.tomcat.host:8080/access</em>) will redirect a user (via a 303 code) to another web page (<em>http://my.tomcat.host:8080/access/sessionId=1234567</em>). Setting up HAProxy I set the frontend engine (my-frontend-https) to receive https requests and send them to the backend (my-backend-https) - which in turn then sends it to the tomcat server as http requests. </p>
  
  <p>This is what haproxy.cfg (for my.haproxy.host) looks like:</p>
  
  <pre><code>frontend my-frontend-https
     bind *:8443 ssl crt /my/certs/server.pem
     mode http
     option httplog
     default_backend my-backend-https
  
  backend my-backend-https
    balance roundrobin
    mode http
    option httplog
    option forwardfor
    server my-tomcat-srv my.tomcat.host:8080 check
  </code></pre>
  
  <p>On sending the following query (<em>https://my.haproxy.host:8443/access</em>) I found that the Location flag being returned from tomcat was of the form: <em>http://my.haproxy.host:80/access/sessionId=1234567</em>. Looking at the tomcat server I found that I had to enable RemoteIPValve class in server.xml and set the httpsServerPort to 8443 (as protocolHeaderHttpsValue - may not have needed to do this bit though since it's a default). This seems to work and I will add more servers to the backend.</p>
  
  <p>So that seems well but  I have a couple of questions:</p>
  
  <ol>
  <li>I noticed that the problem doesn't seem to exist when the frontend engine is http rather than https. That is, the Location field comes back how I would expect to be. Any ideas of the discrepancy?</li>
  <li>Without the settings in the server.xml file it would seem that tomcat knows that I am using a proxy in between my web browser and tomcat. How does it know this? Is there a directive that is being passed to tomcat that tells it is a proxy or is it simpler than that.</li>
  <li><p>If I want another front-end/back-end engine in the same haproxy.cfg file pointing to the same tomcat instance (i.e. lets says the above was load balancing across multiple servers including this one and I want an entry point for just this one) can it be done?
  i.e. the haproxy would have the following lines in it.
  frontend my-frontend-https1
     bind *:9443 ssl crt /my/certs/server.pem
     mode http
     option httplog
     default_backend my-backend-https1</p>
  
  <p>backend my-backend-https1
    balance roundrobin
    mode http
    option httplog
    option forwardfor
    server my-tomcat-srv my.tomcat.host:8080 check</p>
  
  <p>Would the Location field come back as <a href="http://my.haproxy.host:8443/access/sessionId=1234567" rel="nofollow">http://my.haproxy.host:8443/access/sessionId=1234567</a> since that is what is defined in server.xml. Thanks</p></li>
  </ol>
  
  <p>Harold.</p>