I have django app running in subpath example.com/api/
. 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 example.com/back/static/
, when they are in example.com/api/back/static/
.
Also example.com/api/admin
redirects to example.com/admin/login/
, but after manually going to example.com/api/admin/login/
everything works smoothly (but still there are no styles).
My stack is nginx + Django 2.0.5 running in docker container.
Nginx configuration:
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 "";
}
When it comes to Django STATIC_URL
is set to os.path.join(BASE_DIR, "static/")
, FORCE_SCRIPT_NAME
is not set, but when set, it's not working at all.
Any ideas?
[Update]
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:
Run django app via nginx+uwsgi in a subpath
Serving multiple Django applications with Nginx and Gunicorn
I gave up and just created separate subdomain for this project.