nginx 07 - Nginx 캐 시 서비스

2736 단어
Nginx 캐 시 서비스 설정 문법
proxy_cache_path path kes_zone=name:size 
[levels=levels] 
[use_temp_path=on|off]
[inactive=time]
[max_size=size]
[manager_files=number]
[manager_sleep=time]
[manager_threshold=time]
[loader_files=number]
[loader_sleep=time]
[loader_threshold=time]
[purger=on|off]
[purger_files=number]
[purger_sleep=time]
[purger_threshold=time]
(http)
proxy_cache zone|off;
(http、server、location)
proxy_cache_valid [code..] time;
(http、server、location)
  :      
proxy_cache_key string;
(http、server、location)
  :    ,  :proxy_cache_key $scheme$proxy_host$request_uri

Nginx 캐 시 서비스 설정 사례
http{
    upstream test {
        server 192.168.10.10:8080 down;
        server 192.168.10.10:8081 max_fails=1 fail_timeout=10s;
        server 192.168.10.11:8080 backup;
    }
    
    proxy_cache_path /opt/app/cache levels=1:2 keys_zone=imooc_cache:10m max_size=10g inactive=60m use_temp_path=off;
    server {
        listen 80;
        server_name location;
        location / {
        proxy_cache off;
            proxy_pass http://test;
            proxy_cache_valid 200 304 12h;
            proxy_cache_valid any 10m;
            proxy_cache_key $host$uri$is_args$args;
            add_header  Nginx-Cache "$upstream_cache_status";  
            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        }
    }
}

지정 한 캐 시 를 어떻게 청소 합 니까?
  • 방법 1: rm - rf 캐 시 디 렉 터 리 내용
  • 방법 2: 제3자 확장 모듈 ngxcache_purge

  • 일부 페이지 가 캐 시 되 지 않도록 하 는 방법
  • 설정 문법:
  • proxy_no-cache string ...;
    (http、server、location)
  • 설정 사례:
  • server {
        listen 80;
        server_name location;
        
        if ($request_uri ~ ^/(url3|login|register|password\/reset)) {
            set $cookie_nocche 1;
        }
        location / {
        proxy_cache off;
            proxy_pass http://test;
            proxy_cache_valid 200 304 12h;
            proxy_cache_valid any 10m;
            proxy_cache_key $host$uri$is_args$args;
            proxy_no_cache $cookie_nocche $arg_nocache $arg_comment;
            proxy_no_cache $http_pragma $http_authorization;
            add_header  Nginx-Cache "$upstream_cache_status";  
            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        }
    }

    큰 파일 분할 요청
  • 설정 문법:
  • slice size;
    (http、server、location)   :slice 0
  • 장점:    모든 하위 요청 이 받 은 데 이 터 는 하나의 독립 된 파일 을 만 들 고 하나의 요청 이 끊 어 지 며 다른 요청 은 영향 을 받 지 않 습 니 다
  • 단점:    파일 이 크 거나 slice 가 작 을 때 파일 설명자 가 소 진 될 수 있 습 니 다
  • 다음으로 전송:https://www.cnblogs.com/liangjingfu/p/10677108.html

    좋은 웹페이지 즐겨찾기