title: how to deploy django under a suburl behind nginx
body: <p>I have a django application running on <a href="http://localhost:12345" rel="noreferrer">http://localhost:12345</a> .
  I'd like user to access it via url <a href="http://my.server.com/myapp" rel="noreferrer">http://my.server.com/myapp</a> .
  I use nginx to reverse proxy to it like the following:</p>
  
  <pre><code>... ...
  server_name my.server.com;
  location /myapp {
      rewrite /myapp(.*) $1 break;        
      ... ... # proxy param 
      proxy_pass http://localhost:12345;
  }
  ... ...
  </code></pre>
  
  <p>The question is, when configured like the above, how to make the urls in my response pages to have a prefix of "/myapp" so that the nginx can direct them correctly to myapp. E.g., the urls in a page like "/foo/far" ought to be changed to "/myapp/foo/bar" to allow nginx proxy to myapp. 
  what is the right nginx configure to use to achieve this ?</p>
  
  <p>I can use settings variables of django to specify the root url prefix, but it's not flexiable to my mind, since the variable have to be modified according to different nginx configuration(say one day nginx may change the suburl from "/myapp" to "/anotherapp").</p>