title: Deploy Java Web in Tomcat Subfolder Using Reverse Proxy
body: <p>I'm having trouble deploying a Java Web project to Tomcat.</p>
  
  <p>In localhost(development environment), I can deploy it successfully. I can access the project by visiting <code>http://localhost:8080/project</code>.</p>
  
  <p>I tried to deploy it on server. Of course I can access the project using <code>http://server_ip:8080/project</code>.
  As you see, the project is located in <code>TOMCAT_HOME/webapps/project</code>.</p>
  
  <p>When I using it with reverse proxy powered by Nginx. Here's the configuration of Nginx:</p>
  
  <pre><code>server {
      listen       80;
      server_name  example.com;
  
      location / {
          proxy_pass         http://127.0.0.1:8080/project;
      }
  }
  </code></pre>
  
  <p>Normally, I can visiting the project using <code>http://example.com</code> and nginx will fetch the content in <code>http://127.0.0.1:8080/project</code>. It does, but I have trouble getting static files.</p>
  
  <p>I use <code>&lt;c:url&gt;</code> tag to load static files:</p>
  
  <pre><code>&lt;link rel="stylesheet" type="text/css" href="&lt;c:url value="/assets/css/style.css" /&gt;" /&gt;
  </code></pre>
  
  <p>when I access the website using <code>http://server_ip:8080/project</code>, everything works fine. And the value of href will be <code>/project/assets/css/style.css</code>.</p>
  
  <p>But when I access the website using <code>http://example.com</code>, the value of href will still be <code>/project/assets/css/style.css</code>, so I'll get a 404 error. Because this URL means <code>/project/project/assets/css/style.css</code>. However, the file is located in <code>/assets/css/style.css</code></p>
  
  <p>Anyone can help me with the problem? Thx a lot.</p>