1. cache dir 설정

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=cache:2m 



2. cache 사용 설정

server { 

    listen       80; 

    server_name  cached.test.co.kr; 

    access_log  /var/log/nginx/cache-access.log  combined; 

 

    location / { 

        proxy_pass http://localhost:8080; 

        proxy_cache cache; 

        proxy_set_header X-Real-IP  $remote_addr; 

        proxy_set_header X-Forwarded-For $remote_addr; 

        proxy_set_header Host $host; 

  proxy_set_header X-Cache-Status  $upstream_cache_status;

    } 


httpstat   http://proxy.test.co.kr/



3. cache timeout 값 조정

server { 

    listen       80; 

    server_name  micro.test.co.kr; 

 

    access_log  /var/log/nginx/micro-access.log  combined; 

 

    location / { 

        proxy_pass http://127.0.0.1:8080; 

        proxy_cache micro; 

        proxy_cache_valid 200 10s; 

        proxy_set_header X-Real-IP  $remote_addr; 

        proxy_set_header X-Forwarded-For $remote_addr; 

        proxy_set_header Host $host; 

    } 



4. cache stale 값 설정

500, 502, 503, 504 에러가 발생할때 stale cache 사용


server { 

    listen       80; 

    server_name  proxystale.test.co.kr; 

    access_log  /var/log/nginx/proxy-access.log  combined; 

 

    location / { 

        proxy_pass http://127.0.0.1:8000; 

        proxy_set_header X-Real-IP  $remote_addr; 

        proxy_set_header X-Forwarded-For $remote_addr; 

        proxy_set_header Host $host; 

        proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504; 

    } 


5. cache lock 값 설정

location / { 

        proxy_pass http://127.0.0.1:80; 

        proxy_set_header X-Real-IP  $remote_addr; 

        proxy_set_header X-Forwarded-For $remote_addr; 

        proxy_set_header X-Cached $upstream_cache_status; 

        proxy_set_header Host www.verifiedparts.com; 

        proxy_cache_use_stale error updating timeout http_500 http_502 http_503 http_504; 

        proxy_cache_lock on; 

        proxy_cache_lock_timeout 60s; 

    }  


'오픈소스 > nginx' 카테고리의 다른 글

nginx load balancing  (0) 2018.02.05
nginx 접속 제한 (rate limiting)  (0) 2018.02.05
nginx proxy setup  (0) 2018.02.05
blocking setup for nginx  (0) 2018.02.02
nginx redirect  (0) 2018.02.02

+ Recent posts