title: Django - problems with static files when running in subpath
body: <p>I have django app running in subpath <code>example.com/api/</code>. Most of it is rest API (I use django-rest-framework), and all requests are working correctly. But static files has wrong paths everywhere - in admin panel, and in requests page (in django-rest-framework you have frontend to investigate things). Django somehow thinks, that all static files are in <code>example.com/back/static/</code>, when they are in <code>example.com/api/back/static/</code>.</p>
  
  <p>Also <code>example.com/api/admin</code> redirects to <code>example.com/admin/login/</code>, but after manually going to <code>example.com/api/admin/login/</code> everything works smoothly (but still there are no styles).</p>
  
  <p>My stack is nginx + Django 2.0.5 running in docker container.</p>
  
  <p>Nginx configuration:</p>
  
  <pre><code>location /api/ {
      proxy_pass            http://localhost:8000/;
      proxy_read_timeout    90;
      proxy_connect_timeout 90;
      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      Proxy "";
  }
  </code></pre>
  
  <p>When it comes to Django <code>STATIC_URL</code> is set to <code>os.path.join(BASE_DIR, "static/")</code>, <code>FORCE_SCRIPT_NAME</code> is not set, but when set, it's not working at all.</p>
  
  <p>Any ideas?</p>
  
  <p><strong>[Update]</strong></p>
  
  <p>After some hours of fight, I gave up. The problem is connected with uwsgi not recognizing that it's running in subpath. Here are some links which can be useful for someone with similar problem:</p>
  
  <p><a href="https://stackoverflow.com/questions/11292217/run-django-app-via-nginxuwsgi-in-a-subpath">Run django app via nginx+uwsgi in a subpath</a></p>
  
  <p><a href="https://integricho.github.io/2014/02/22/running-django-on-a-subpath/" rel="noreferrer">Running Django on a subpath
  </a></p>
  
  <p><a href="http://michal.karzynski.pl/blog/2013/10/29/serving-multiple-django-applications-with-nginx-gunicorn-supervisor/" rel="noreferrer">Serving multiple Django applications with Nginx and Gunicorn
  </a></p>
  
  <p><a href="http://spazzy757.com/wsgi-routing/" rel="noreferrer">Django WSGI routing
  </a></p>
  
  <p>I gave up and just created separate subdomain for this project.</p>