django - 注销不起作用,在 nginx 上缓存,如何允许注销?

标签 django caching nginx

我已经缓存了所有内容,如果我登录我的帐户,您将无法再注销)退出时如何退出?我需要知道如何删除cookies和 session !我什么时候退出!

P.S. if i'll disable caching on nginx level, everything works fine, problem in nginx



nginx 配置
    gzip on;
    gzip_disable "msie6";

    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    proxy_connect_timeout 5;
    proxy_send_timeout 10;
    proxy_read_timeout 10;
    proxy_buffering on;
    proxy_buffer_size 16k;
    proxy_buffers 24 16k;
    proxy_busy_buffers_size 64k;
    proxy_temp_file_write_size 64k;

    proxy_temp_path /tmp/nginx/proxy_temp;
    add_header X-Cache-Status $upstream_cache_status;
    proxy_cache_path /tmp/nginx/cache levels=1:2 keys_zone=first_zone:100m;
    proxy_cache one;
    proxy_cache_valid any 30d;
    proxy_cache_key $scheme$proxy_host$request_uri$cookie_US;

服务器配置
upstream some site {
  server unix:/webapps/some/run/gunicorn.sock fail_timeout=0;
}

server {
    listen   80;
    server_name server name;
    expires 7d;
    client_max_body_size 4G;

    access_log /webapps/some/logs/nginx-access.log;
    error_log /webapps/some/logs/nginx-error.log;
    error_log /webapps/some/logs/nginx-crit-error.log crit;
    error_log /webapps/some/logs/nginx-debug.log debug; 
    location /static/ {
        alias   /webapps/some/static/;
    }

    location /media/ {
        alias   /webapps/some/media/;
    }
    location ~* ^(?!/media).*.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
        root root_path;
        expires 7d;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        access_log off;
    }    
    location ~* ^(?!/static).*.(?:css|js|html)$ {
        root root_path;
        expires 7d;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        access_log off;
    }     

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_cache one;
        proxy_cache_min_uses 1;
        proxy_cache_use_stale error timeout;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        # proxy_set_header X-Forwarded-Proto https;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        if (!-f $request_filename) {
            proxy_pass http://some;
            break;
        }
    }
    error_page 404 /404.html;
    location = /error_404.html {
        root /webapps/some/src/templates;
    }

    error_page  500 502 503 504 /500.html;
    location = /error_500.html {
        root /webapps/some/src/templates;
    }
}

最佳答案

而不是用 GET 注销请求,更改您的注销 View 以接受表单 POST .
POST不应缓存请求。

这具有额外的安全优势,可以防止用户使用 iframe 或恶意链接注销(即: https://example.com/logout/ ,假设您没有禁用 django 的 CSRF 保护)。

注意:有一个 ticket on django's bug tracker related to this issue .

关于django - 注销不起作用,在 nginx 上缓存,如何允许注销?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47990891/

相关文章:

Django 表单未使用 ModelChoiceField 保存 -foreignkey

Django enctype ="multipart/form-data"未设置 POST 数据

html - 尝试在 Django 中的表单上使用脆皮表单过滤器时收到 'invalid form: crispy' 错误,但仅在一个 django 应用程序中而不是在另一个应用程序中?

database - Redis Pub/Sub 和 Redis Stream 之间的主要区别是什么?

python - 导入请求处理器模块 Django 时出错

caching - Redis 作为缓存和使用相同实例的队列

php - 如何在mysql连接失败时打开缓存?

amazon-web-services - Kibana没有正确加载。使用Nginx反向代理设置后

docker - 在kubernetes上通过Nginx Ingress中的服务公开容器中的基本路径

asp.net apache2/nginx OutputCache问题