title: Thymeleaf template (in Spring boot application) behind reverse proxy not forming url's correctly
body: <p>I have some trouble getting Thymeleaf to form relative URL's correctly when it is used on a server behind a reverse proxy (nginx in my case).</p>
  
  <p>Let's say I have the following location in nginx:</p>
  
  <pre><code>location /app {
      proxy_pass http://10.0.0.0:8080;
  }
  </code></pre>
  
  <p>I have the following Thymeleaf 3 page (<code>index.html</code>):</p>
  
  <pre><code>&lt;html xmlns:th="http://www.thymeleaf.org"&gt;
  
  &lt;head&gt;
      &lt;link rel="stylesheet" th:href="@{/css/some.css}" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
      Hello world!
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The server used is an embedded Tomcat server (Spring boot), running at context <code>/</code>.</p>
  
  <p>When I send a request to <code>http://example.com/app</code>, then I get the <code>index.html</code> page as response. The css cannot be retrieved however, because when the URL is constructed in the Thymleaf template, it uses the context path of the tomcat server, which is <code>/</code>. The constructed url in the <code>index.html</code> looks as follows:</p>
  
  <pre><code>http://example.com/css/some.css
  </code></pre>
  
  <p>This obviously results in a 404 not found.
  The URL needs to be formed as follows:</p>
  
  <pre><code>http://example.com/app/css/some.css
  </code></pre>
  
  <p>What do I need to configure to let Thymeleaf form the URL as <code>http://example.com/app/css/some.css</code>? I would rather not hardcode the base URL anywhere for certain profiles or something like that. I think I need to add something to the nginx configuration, but I'm not sure what exactly.</p>