Nginx

nginx 記憶體工作錯誤,nginx 記憶體身份驗證系統,註銷不起作用(在 DJANGO 上),如何解決?

  • January 4, 2018

nginx 正在記憶體所有內容,如果我登錄到系統,那麼在記憶體到期之前我將無法退出它,因為我是從帳戶中註銷,我需要知道如何刪除 cookie 和會話!

預設情況下,Django 本身在退出時會刪除 cookie 和會話,使用標準方法從開發人員 django 中退出帳戶,我使用它,如果您在 nginx 禁用記憶體,那麼一切正常!

nginx 配置 “/etc/nginx/nginx.conf”

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

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=one:100m;
proxy_cache_path /tmp/nginx/cache2 levels=1:2 keys_zone=two:100m;
proxy_cache one;
proxy_cache_valid any 30d;
proxy_cache_key $scheme$proxy_host$request_uri$cookie_US;

我的伺服器配置

upstream theband {
 # fail_timeout=0 means we always retry an upstream even if it failed
 # to return a good HTTP response (in case the Unicorn master nukes a
 # ssingle worker for timing out).

 server unix:/webapps/theband/run/gunicorn.sock fail_timeout=0;
}

server {

   listen   80;
   server_name 207.154.232.99;
   expires 35d;
   client_max_body_size 4G;

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

   location /media/ {
       alias   /webapps/theband/media/;
   }
   location ~* ^(?!/media).*.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
       alias /tmp/nginx/trash/trash_media;
       expires 35d;
       add_header Pragma public;
       add_header Cache-Control "public, must-revalidate, proxy-revalidate";
       access_log off;
   }    
   location ~* ^(?!/static).*.(?:css|js|html)$ {
   root /tmp/nginx/trash/trash_static;
       expires 35d;
       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 updating http_500 http_502 http_503 http_504;

       # an HTTP header important enough to have its own Wikipedia entry:
       #   http://en.wikipedia.org/wiki/X-Forwarded-For
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

       # enable this if and only if you use HTTPS, this helps Rack
       # set the proper protocol for doing redirects:
       # proxy_set_header X-Forwarded-Proto https;

       # pass the Host: header from the client right along so redirects
       # can be set properly within the Rack application
       proxy_set_header Host $http_host;

       # we don't want nginx trying to do something clever with
       # redirects, we set the Host: header above already.
       proxy_redirect off;

       # set "proxy_buffering off" *only* for Rainbows! when doing
       # Comet/long-poll stuff.  It's also safe to set if you're
       # using only serving fast clients with Unicorn + nginx.
       # Otherwise you _want_ nginx to buffer responses to slow
       # clients, really.
       #proxy_buffering off;

       # Try to serve static files from nginx, no point in making an
       # *application* server like Unicorn/Rainbows! serve static files.
       if (!-f $request_filename) {
           proxy_pass http://theband;
           break;
       }
   }
   error_page 404 /error_404.html;
   location = /error_404.html {
       root /webapps/theband/src/templates;
   }

   # Error pages
   error_page  500 502 503 504 /error_500.html;
   location = /error_500.html {
       root /webapps/theband/src/templates;
   }
}

我哭了,我花了很多時間解決這個問題,雖然我知道問題是什麼,以及如何大致解決它,但我只是添加了 SIMPLE,SIMPLY 1 行程式碼…. CARL 我們有把這個proxy_pass http://theband;

請殺了我(…

像這樣製作,特定網址的記憶體將被禁用,並且可以訪問頁面!

location /accounts/logout {
   proxy_no_cache 1;
   proxy_cache_bypass 1;
   add_header Last-Modified $date_gmt;
   add_header Cache-Control 'no-cache, must-revalidate, proxy-revalidate, max-age=0';
   if_modified_since off;
   expires -1;
   proxy_pass http://theband;
   etag off;

}

引用自:https://serverfault.com/questions/889840