title: Domain name and port based proxy
body: <p>I think I finally grasped how Docker works, so I am getting ready for the next step: cramming a whole bunch of unrelated applications into a single server with a single public IP. Say, for example, that I have a number of legacy Apache2-VHost-based web-sites, so the best I could figure was to run a LAMP container to replicate the current situation, and improve later. For argument sake, here is what I have a container at 172.17.0.2:80 that serves</p>
  
  <pre><code>http://www.foo.com
  http://blog.foo.com
  http://www.bar.com
  </code></pre>
  
  <p>Quite straightforward: publishing port 80 lets me correctly access all those sites. Next, I have two services that I need to run, so I built two containers</p>
  
  <pre><code>service-a -&gt; 172.17.0.3:3000
  service-b -&gt; 172.17.0.4:5000
  </code></pre>
  
  <p>and all is good, I can privately access those services from my docker host. The trouble comes when I want to publicly restrict access to <code>service-a</code> through <code>service-a.bar.com:80</code> only, and to <code>service-b</code> through <code>www.foo.com:5000</code> only. A lot of reading after, it would seem that I have to create a dreadful artefact called a proxy, or reverse-proxy, to make things more confusing. I have no idea what I'm doing, so I dove nose-first into nginx -- which I had never used before -- because someone told me it's better than Apache at dealing with lots of small tasks and requests -- not that I would know how to turn Apache into a proxy, mind you. Anyway, nginx sounded perfect for a thing that has to take a request a pass it onto another server, so I started reading docs and I produced the following (in addition to the correctly working vhosts):</p>
  
  <pre><code>upstream service-a-bar-com-80 {
          server 172.17.0.3:3000;
  }
  
  server {
          server_name service-a.bar.com;
          listen 80;
  
          location / {
                  proxy_pass http://service-a-bar-com-80;
                  proxy_redirect off;
          }
  }
  
  upstream www-foo-com-5000 {
          server 172.17.0.4:5000;
  }
  
  server {
          server_name www.foo.com;
          listen 5000;
  
          location / {
                  proxy_pass http://www-foo-com-5000;
                  proxy_redirect off;
          }
  }
  </code></pre>
  
  <p>Which somewhat works, until I access <a href="http://blog.bar.com:5000" rel="nofollow">http://blog.bar.com:5000</a> which brings up <code>service-b</code>. So, my question is: what am I doing wrong?</p>