URL resolution error using Gunicorn, Nginx, and Django

Pierre Alex

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... :(

GwynBleidD

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).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error Logging in Nginx+Gunicorn+Supervisor+Django

From Dev

External IP error on Django + Nginx + Gunicorn setup

From Dev

External IP error on Django + Nginx + Gunicorn setup

From Dev

nginx and gunicorn for a django project

From Dev

restrict access to the admin url by ip in django with nginx and gunicorn

From Dev

500 internal server error when deploy django with gunicorn and nginx

From Dev

Bad Request (400) and 502 error: Nginx, gunicorn, django

From Dev

Django, nginx, gunicorn: why on some page gives Server Error (500)?

From Dev

Bad Request (400) and 502 error: Nginx, gunicorn, django

From Dev

gunicorn, nginx, and using port 80 for running a django web application

From Dev

Deploying Django app to AWS EC2 using Nginx and Gunicorn

From Dev

Multiple Django app using nginx and gunicorn on Ubuntu 14.04 trusty server

From Dev

Deploying Django project with Gunicorn and nginx

From Dev

Django Nginx Gunicorn = 504 Timeout

From Dev

Static files in Nginx, Gunicorn in Django

From Dev

Django Nginx Gunicorn = 504 Timeout

From Dev

Deploying Django project with Gunicorn and nginx

From Dev

nginx, gunicorn and django timing out

From Dev

Error Logging in Django and Gunicorn

From Dev

Django Gunicorn error

From Dev

Nginx, Flask, Gunicorn 502 Error

From Dev

Error handling request with gunicorn and nginx

From Dev

What is the purpose of using nginx with gunicorn?

From Dev

Django+Gunicorn+nginx Internal Server Error, where is the error and how to fix it?

From Dev

'Invalid input syntax for type inet' db error in Django app with postgres and Gunicorn+Nginx as reverse proxy

From Dev

nginx only passing base '/' url to gunicorn

From Dev

Error running django with gunicorn and circus

From Dev

Django Gunicorn no module named error

From Dev

Django, Nginx, Gunicorn static files not working

Related Related

  1. 1

    Error Logging in Nginx+Gunicorn+Supervisor+Django

  2. 2

    External IP error on Django + Nginx + Gunicorn setup

  3. 3

    External IP error on Django + Nginx + Gunicorn setup

  4. 4

    nginx and gunicorn for a django project

  5. 5

    restrict access to the admin url by ip in django with nginx and gunicorn

  6. 6

    500 internal server error when deploy django with gunicorn and nginx

  7. 7

    Bad Request (400) and 502 error: Nginx, gunicorn, django

  8. 8

    Django, nginx, gunicorn: why on some page gives Server Error (500)?

  9. 9

    Bad Request (400) and 502 error: Nginx, gunicorn, django

  10. 10

    gunicorn, nginx, and using port 80 for running a django web application

  11. 11

    Deploying Django app to AWS EC2 using Nginx and Gunicorn

  12. 12

    Multiple Django app using nginx and gunicorn on Ubuntu 14.04 trusty server

  13. 13

    Deploying Django project with Gunicorn and nginx

  14. 14

    Django Nginx Gunicorn = 504 Timeout

  15. 15

    Static files in Nginx, Gunicorn in Django

  16. 16

    Django Nginx Gunicorn = 504 Timeout

  17. 17

    Deploying Django project with Gunicorn and nginx

  18. 18

    nginx, gunicorn and django timing out

  19. 19

    Error Logging in Django and Gunicorn

  20. 20

    Django Gunicorn error

  21. 21

    Nginx, Flask, Gunicorn 502 Error

  22. 22

    Error handling request with gunicorn and nginx

  23. 23

    What is the purpose of using nginx with gunicorn?

  24. 24

    Django+Gunicorn+nginx Internal Server Error, where is the error and how to fix it?

  25. 25

    'Invalid input syntax for type inet' db error in Django app with postgres and Gunicorn+Nginx as reverse proxy

  26. 26

    nginx only passing base '/' url to gunicorn

  27. 27

    Error running django with gunicorn and circus

  28. 28

    Django Gunicorn no module named error

  29. 29

    Django, Nginx, Gunicorn static files not working

HotTag

Archive