title: Spring Boot with embedded Tomcat behind Apache proxy
body: <p>We have a Spring Boot (Spring MVC) app with embedded Tomcat on a dedicated appserver behind an Apache SSL proxy.</p>
  <p>The SSL port on the proxy server is 4433, forwarding to port 8080 on the appserver.</p>
  <p>So the URL to the proxy server is forwarding like:</p>
  <pre><code>https://proxyserver:4433/appname   &gt;&gt;forward&gt;&gt;   http://appserver:8080/
  </code></pre>
  <p>When running WITHOUT proxy, the first thing that happens is that<br />
  Spring Security redirects the request, like:</p>
  <pre><code>http://appserver:8080/   &gt;&gt;redirect&gt;&gt;   http://appserver:8080/login
  </code></pre>
  <p>to display the login form, by extending <code>WebSecurityConfigurerAdapter</code> with</p>
  <pre><code>  ...
    httpSecurity.formLogin().loginPage(&quot;/login&quot;) ...
    ...
  </code></pre>
  <p>It works fine without the proxy, but WITH proxy the redirect needs to be changed,<br />
  so Spring should instead redirect to the corresponding proxy URL, like:</p>
  <pre><code>http://appserver:8080/   &gt;&gt;redirect&gt;&gt;   https://proxyserver:4433/appname/login
  </code></pre>
  <p>but no success yet.</p>
  <p>I am trying to apply this solution:
  <a href="https://docs.spring.io/spring-boot/docs/1.1.1.RELEASE/reference/html/howto-embedded-servlet-containers.html#howto-use-tomcat-behind-a-proxy-server" rel="noreferrer">59.8 Use Tomcat behind a front-end proxy server</a></p>
  <p>We have configured <a href="https://en.wikipedia.org/wiki/Mod_proxy" rel="noreferrer"><em>mod_proxy</em></a> in Apache, and verified that it sends the expected headers:</p>
  <pre><code>X-Forwarded-For: xxx.xxx.xxx.xxx
  X-Forwarded-Host: proxyserver
  X-Forwarded-Port: 4433
  X-Forwarded-Proto: https
  </code></pre>
  <p>The application is started with parameters:</p>
  <pre><code>export ARG1='-Dserver.tomcat.protocol-header=x-forwarded-proto' 
  export ARG2='-Dserver.tomcat.remote-ip-header=x-forwarded-for'
  java $ARG1 $ARG2 -jar webapp.jar
  </code></pre>
  <p>Still the redirect does not work.</p>
  <p>It will keep redirecting locally, to  <code>http://appserver:8080/login</code> which is not available to the clients.</p>
  <p>Is there anything else we need to do to make this scenario work?</p>
  <br>
  <h2>UPDATE</h2>
  <p>Also, I am concerned about the &quot;/appname&quot; part in the proxy URL. On the appserver the application is rooted at &quot;/&quot;. How should Spring be instructed that &quot;/appname&quot; should be included in all URLs sent back to the clients, when going thru the proxy?</p>