Reputation: 473
I have a strange error occuring only when using Gunicorn :
I have a setup Nginx + a django project with the following config :
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header SCRIPT_NAME /;
}
When I use the django development server (1.7.5) using:
./manage.py runserver 127.0.0.1:8080
Everything works fine.
But when I run
gunicorn -b :8080 --forwarded-allow-ips="*" --proxy-allow-from="*" app.wsgi
I only get 404 errors (django is receiving requests as I have the debug messages).
These errors are strange because the variable urlpatterns (https://github.com/django/django/blob/1.7.5/django/views/debug.py#L1102) is not set. I only obtain the reason variable (https://github.com/django/django/blob/1.7.5/django/views/debug.py#L1119) set to :
{u'path': u'x/'}
as I requested http://domain.something.com/x/
What bothers be the most is that the basic server that comes with django works fine... :(
Upvotes: 2
Views: 1563
Reputation: 20539
Removing
proxy_set_header SCRIPT_NAME /;
from nginx config will do the job. It is how django treats SCRIPT_NAME
header: when present, django will cut that value from the front of URL when resolving it, and will add it back to the front of the url when reversing it. That way you can tell django that all urls should be relative to certain directory without touching anything in your project. SCRIPT_NAME
should be set without trailing / so correct value for root directory of your domain is an empty string (or total absence of SCRIPT_NAME
).
Upvotes: 4