2016-10-16 2 views
0

내 질문에 컨텍스트를 작성합니다 ...nginx를 사용하여 여러 인스턴스에서 캐시 공유

Node.js 웹 앱이 정상적으로 작동합니다. AWS (Elastic Load Balancing, 클래식 모드)에 여러 EC2 인스턴스가있는 자동 확장 그룹이있는로드 밸런서가 있습니다.

각 EC2 인스턴스에는 Nginx 리버스 프록시가 설치되어있어 PM2 및 Node.js (Express)와 잘 작동합니다. Nginx를 사용하여 정적 파일 캐싱, 요청 캐싱, https 및 다른 작업.

Nginx를 사용하는 모든 인스턴스간에 캐시를 공유하고 각 컴퓨터의 메모리 캐시를 각각 사용하지 않는 방법을 알아야합니다. Memcache o Redis를 사용하고 싶습니다.하지만 하나를 선택해야합니다. Redis를 선호합니다. 나는 아무 대답없이 ServerFault에서이 질문을 발견

proxy_cache_path /cache/nginx levels=1:2 keys_zone=cache_zone_name:10m; 

location/{ 
      #root html; 
      #index index.html index.htm; 

      #Config proxy inverse cache 
      proxy_pass http://localhost:3000; 
      proxy_http_version 1.1; 
      proxy_set_header Upgrade $http_upgrade; 
      proxy_set_header Connection 'upgrade'; 
      proxy_set_header Host $host; 
      proxy_cache_bypass $http_upgrade; 

      # Add cache debugging header 
      add_header X-Cache-Status $upstream_cache_status; 

      # Configure cache 
      proxy_cache  cache_zone_name; 
      proxy_cache_valid any 1m; 
      proxy_cache_key $scheme$host$request_uri; 

     } 

:

내가이 순간 (단지 중요한 코드)에서 일하고 있어요 방법 예입니다.

감사합니다.

편집 : 중요 사항, 나는 캐시 성능 :

답변

0

의 nginx 저장에 영향을 미치지 않는 솔루션을 필요로 파일에 데이터를하지만, 컨텐츠 위치에 cache_keys (URL에 대한 고유 식별자) 매핑 메모리

예에 저장됩니다 : 당신은 index.html을의 내용에/캐시/nginx를/C/29/b7f54b2df7773722d382f4809d65029c 및 위치 cache_key의 MD5가 메모리에 저장됩니다 저장됩니다 의미 URL http://localhost/index.html을 (액세스 할 때 md5 (httplocalhostindex.html) ->/캐시/nginx를/C/29/b7f54b2df7773722d382f4809d65029c)

Nginx와는

참조 성능을 캐싱에 영향을 줄이 로컬 스토리지에 매핑 또는 공유 메모리 (레디 스/memcached와)를 유지할 수 없습니다

: http://nginx.org/en/docs/http/ngx_http_proxy_module.html (키워드 검색 keys_zone)

관련 문제