I've got Django running behind Nginx with fastcgi_pass
. I run Django at a subpath like /django/sample
.
location /django/sample {
include fastcgi_params;
fastcgi_pass 127.0.0.1:8025;
}
I use FORCE_SCRIPT_NAME
in the Django settings module, which seems to fix all the issues I was having in regards to it running at a subpath.
In settings.py:
FORCE_SCRIPT_NAME = "/django/sample/"
I go here to login with admin (and correctly get the admin UI):
http://server/django/sample/admin
But when I submit, it redirects to:
http://server/django/sample/django/sample/admin
What's really strange is that if I change FORCE_SCRIPT_NAME=""
the login works.
BUT, then all of the links in the admin page are /admin
, not /django/sample/admin/
What the heck am I missing? Setting FORCE_SCRIPT_NAME="/django/sample/"
seems to fix everything except admin login.
Any ideas?
UPDATE:
I've also tried using fastcgi_split_path_info
in nginx conf (and take out FORCE_SCRIPT_NAME
in settings). Again, that fixes all the path issues except the admin login redirect.
conf like this:
location /django/sample {
fastcgi_split_path_info ^(/django/sample)(.*)$;
include fastcgi_params;
fastcgi_pass 127.0.0.1:8025;
}
FYI, I gave up. All the documentation says it's supposed to be easy. But it's too much of a pain to deal with. I instead am requiring our Django apps to use a subdomain and setup a vhost with the server. This way Django can run at document root "/"
FWIW, I've written up a solution in another thread that's worked for me when I have a proxy server in front of a Django server using wsgi.
As I remember troubleshooting this a long time ago... you saw the out-of-sync behavior because of the way the Django admin sets up and processes the next
param on the form submit.
Based on my experience, Django sites should definitely use FORCE_SCRIPT_NAME
to modify the way your backend generates links, and your proxy server should also strip out the subfolder (i.e. script-name) part of the path.
The other thread:
Host Django on subfolder
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With