title: Multiple Docker containers with Nginx proxy_pass
body: <p>I have the following setup:</p>
  
  <ul>
  <li>1 machine with Docker installed</li>
  <li>1 domain name (for example <code>mydomain.com</code>)</li>
  <li>3 containers
  
  <ul>
  <li>Portainer (listening on port 9000)</li>
  <li>Jupyter (listening on port 8888)</li>
  <li>Nginx</li>
  </ul></li>
  </ul>
  
  <p>The problem im having is proxying the request from outside (using the <code>nginx</code> container). So when im accessing <code>mydomain.com/juputer</code> should lead to the <code>jupyter</code> container and <code>mydomain.com/portainer</code> should lead to the <code>portainer</code> container. Accessing both containers from the local machine is fine. </p>
  
  <p>I've managed to make the <code>prtainer</code> container accessible from outside but can't make it work for the other containers. </p>
  
  <p>When accessing <code>portainer</code> via <code>mydomain.com/portainer</code> all links are redirected correctly (<code>mydomain.com/portainer/#/dashboard</code>, <code>mydomain.com/portainer/#/containers</code> etc) But when try to access <code>jupyter</code> container im getting 404 and the url is changed to <code>mydomain.com/tree?</code>. <code>tree?</code> is part of Jupyter but i was expecting the link to be <code>mydomain.com/jupyter/tree?</code></p>
  
  <p>I've tried few other configuration options in <code>nginx.conf</code> but nothing seems to work for me</p>
  
  <p>Is this something that can be fixed from <code>Nginx</code> side or its application specific (should edit the configuration of the apps if possible)</p>
  
  <p>nginx.conf:</p>
  
  <pre><code>worker_processes 1;
  
  events { worker_connections 1024; }
  
  http {
  
  log_format compression '$remote_addr - $remote_user [$time_local] '
      '"$request" $status $upstream_addr '
      '"$http_referer" "$http_user_agent" "$gzip_ratio"';
  
  #172.17.0.2 and 172.17.0.4 are the containers internal ip
  #ips will be replaced by names in the future
  
  upstream portainer {
      server 172.17.0.2:9000;
  }
  
  upstream jupyter {
      server 172.17.0.4:8888;
  }   
  
  server {
      listen 80;
      access_log /var/log/nginx/access.log compression;
  
      location /portainer/ {
          proxy_pass         http://portainer/;
          proxy_redirect     off;
          proxy_set_header   Host $host;
          proxy_set_header   X-Real-IP $remote_addr;
          proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header   X-Forwarded-Host $server_name;
      }
  
      location /jupyter/ {
          proxy_pass         http://jupyter/;
          proxy_redirect     off;
          proxy_set_header   Host $host;
          proxy_set_header   X-Real-IP $remote_addr;
          proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header   X-Forwarded-Host $server_name;
      }
  }
  </code></pre>
  
  <p>}</p>