Django + Gunicorn + Nginx = CSRF cookie not set -


i've set django behind nginx gunicorn, when try log in admin panel, get:

forbidden (403) csrf verification failed. request aborted.  reason given failure: csrf cookie not set. 

this weird because works fine if run locally. however, behind nginx fails when run using "python manage.py runserver 0.0.0.0:8000" , "python manage.py run_gunicorn".

settings.py:

middleware_classes = (     'django.middleware.common.commonmiddleware',     'django.contrib.sessions.middleware.sessionmiddleware',     'django.middleware.csrf.csrfviewmiddleware',     'django.contrib.auth.middleware.authenticationmiddleware',     'django.contrib.messages.middleware.messagemiddleware',     # cors support     'corsheaders.middleware.corsmiddleware',     # uncomment next line simple clickjacking protection:     # 'django.middleware.clickjacking.xframeoptionsmiddleware', ) 

nginx.conf:

server {         listen 8080;         server_name  example.com;         access_log  /var/log/nginx/example.com.access.log;         error_log  /var/log/nginx/example.com.error.log info;          keepalive_timeout 5;         location /assets/grappelli/ {                 alias /var/www/example.com/virtualenv/lib/python2.6/site-packages/grappelli/static/grappelli/;         }          location /assets/ { # static_url                 alias /var/www/example.com/popcornhour/assets/; # static_root                 expires 30d;         }  location / {         proxy_pass_header server;         proxy_set_header host $http_host;         proxy_redirect off;         proxy_set_header x-real-ip $remote_addr;         proxy_set_header x-scheme $scheme;         proxy_connect_timeout 10;         proxy_read_timeout 10;         proxy_pass http://localhost:8000/;     }     # serve if upstream not available or crashes     error_page 500 502 503 504 /media/50x.html;  } 

many help!

i found out why failing -- though have varnish disabled domain, still messed headers , cookies, disabled :)


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -