title: How can a node.js express application be deployed behind HAProxy?
body: <p>I have a node.js express application running on machine1 on port 3000. I can successfully access my application via machine1:3000</p>
  
  <p>I have HAProxy running at machine2. I updated haproxy.cfg as follows</p>
  
  <pre><code>frontend main *:80
      acl url_mynodeapp path_beg -i /mynodeapp
  
      use_backend mynodeapp if url_mynodeapp
  
  backend mynodeapp
      mode http
      reqrep ^([^\ ]*\ /)mynodeapp[/]?(.*)     \1\2
      balance roundrobin
      server machine1 1.1.1.1:3000
  </code></pre>
  
  <p>I can now hit my application at machine2/mynodeapp. However all relative links are now broken, including css and javascript (since they point to machine2 instead of machine2/mynodeapp). </p>
  
  <p>How do you deploy an express application behind a proxy? How do you deploy an express application with a subfolder? I am coming from the java world were all web applications are name spaced inside the servlet container, thus giving each application its own subfolder.</p>
  
  <p>Thanks,</p>
  
  <p>Nathan </p>