title: multiple django apps with nginx proxy_pass and rewrite
body: <p>I have a single django-admin app named <code>myapp</code> that I would like to deploy multiple instances of on different physical boxes, one per customer.  However, I'd like them all to be accessed from a similar domain, <code>mydomain.com/customer1/myapp</code>.</p>
  
  <p>I've fiddled with specific proxy settings and tried multiple things suggested on SO, but none quite fit my use case... and since I know very little about both <code>nginx</code> and <code>django</code> I am at a loss!</p>
  
  <p>My current nginx.conf is:</p>
  
  <pre><code>server {
      listen 80;
      server_name myserver.com
  
      location ^~ /static {
          alias /path/to/static/files/;
      }
  #    location / {
  #        proxy_pass http://127.0.0.1:8001;
  #    }
      location ^~ /customer1/myapp/static {
          alias /path/to/static/files/;
      }
      location /customer1/myapp {
          rewrite ^/customer1/myapp/(/?)(.*) /$2 break;
          proxy_pass http://127.0.0.1:8001;
      }
  }
  </code></pre>
  
  <p>I can get to the login screen as expected via <code>myserver.com/customer1/myapp/admin</code>.  However when I attempt to log in, nginx rewrites my url to <code>myserver.com/admin</code> which isn't a valid url.  How do I keep nginx from actually rewriting the url and only change the url that is passed on to <code>127.0.0.1:8001</code>?</p>
  
  <p>FWIW, I am using gunicorn to serve with <code>gunicorn -b 127.0.0.1:8001 -n myapp</code>.  If I uncomment the <code>/</code> location and remove the last two location blocks, the app works great.</p>
  
  <p>I am far from set on this approach if there are alternatives. The goal is to avoid modifying django code for each deployment and instead just add minimal code to the nginx.conf for new deployments.</p>