2016-06-15 1 views
1

Google은 검색 봇 및 skype와 같은 다른 응용 프로그램에서 렌더링해야하는 각도의 프런트 엔드가있는 사이트를 가지고 있습니다.이 사이트는 페이지 미리보기를 만들 수 있습니다. 우리는 nginx를 사용합니다. nginx는 우리 서버에 설치되어있는 봇의 사전 요청 요청을 프록 싱하도록 설정합니다. 그러나이 경우 페이지 중 하나를 사전 렌더링하는 데 약 15 초가 걸립니다.nginx를 통해 캐싱하는 방법 prerender.io의 결과

그래서 질문은 사전 렌더링의 설정 캐싱 결과가 어떻게됩니까?

I가 이미 시도 : 캐싱 넣어 설정을 frontend.conf에

proxy_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=STATIC:10m max_size=1G; 
proxy_temp_path /var/lib/nginx/proxy 1 2; 

server { 

location @prerender { 
..................... 
proxy_cache   STATIC; 
proxy_cache_valid  1d; 
if ($prerender = 1) { 
rewrite .* /$scheme://$host:$server_port$request_uri? break; 
proxy_pass http://10.0.2.2:3000; 
}}} 

경우 prerender.io

작업 그리고 다른 nginx를, 설정을 통해이 일을 시도와 10.0.2.2 서버 캐시 프록시 같은. frotnend.conf에서 모든 캐싱 설정에 주석을 달고 다른 nginx에 넣습니다. 하지만 여전히 같은 문제가 있습니다. 페이지 렌더링에는 15 초가 걸리고 nginx는 캐싱을하지 않습니다.

UDP.

나는 nginx의 다른 구성을 시도했지만 여전히 문제가 있습니다. 스키마

web-browser(http://myapp.local) > |AppServer(frontend) is a virtual Server|(proxy_pass) > to > |nginx with proxy cache| > to > |prerender| 

프록시 cache.conf 같은

proxy_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=STATIC:10m max_size=1G; 
proxy_temp_path /var/lib/nginx/proxy 1 2; 
server { 
.............................. 
    location/{ 

      proxy_cache   STATIC; 
      proxy_ignore_headers Cache-Control; 
      proxy_ignore_headers X-Accel-Expires; 
      proxy_ignore_headers Expires; 
      proxy_cache_methods GET; 
      proxy_cache_valid  any 1d; # 200 
        #proxy_cache_key $host$uri$is_args$args; 

      proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; 

    proxy_pass http://127.0.0.1:3000; 
    }} 

보인다 그리고 캐시에 대한 로깅을 구성합니다. 내가 로그에서 서버에 요청을 할 때 나는이 얻을 :

사전 렌더링의 로그에서
GET /http://myweb.local:80/ HTTP/1.0 "302" 20 "-" "10.0.2.2" "skype" "-" "MISS" "127.0.0.1:3000" "0.388" "0.389" 
GET /http://myweb.local:80/en/ HTTP/1.0 "200" 14685 "-" "10.0.2.2" "skype" "-" "MISS" "127.0.0.1:3000" "1.261" "1.263" 
GET /http://myweb.local:80/ HTTP/1.0 "302" 20 "-" "10.0.2.2" "skype" "-" "HIT" "-" "-" "0.001" 
GET /http://myweb.local:80/en/ HTTP/1.0 "200" 14689 "-" "10.0.2.2" "skype" "-" "MISS" "127.0.0.1:3000" "1.249" "1.251" 

:

2016-06-15T14:05:57.880Z getting http://myweb.local:80/en/ 
2016-06-15T14:05:59.131Z got 200 in 1251ms for http://myweb.local:80/en/ 
2016-06-15T14:06:00.332Z getting http://myweb.local:80/en/ 
2016-06-15T14:06:01.885Z got 200 in 1553ms for http://myweb.local:80/en/ 

답변

0

이 문제가 해결되었습니다. 다른 헤더를 추가해야합니다. proxy_ignore_headers Set-Cookie;. 그래서 nginx를 통한 캐시 프리 렌더링 설정은 다음과 같습니다 :

proxy_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=2g; 

server { 
....................... 
location/{ 
      try_files $uri @prerender; 
    } 
    location @prerender { 
      set $prerender 0; 
....................... 
      proxy_cache   STATIC; 
      proxy_cache_valid any 1d; 
      proxy_ignore_headers Cache-Control; 
      proxy_ignore_headers X-Accel-Expires; 
      proxy_ignore_headers Set-Cookie; 
      proxy_ignore_headers Expires; 
      proxy_cache_key $host$uri$is_args$args; 
      proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; 

      if ($prerender = 1) { 
        rewrite .* /$scheme://$host:$server_port$request_uri? break; 
        proxy_pass http://10.0.2.2:3000; 
      } 
0

사전 렌더링 서버 자체에 캐싱을 추가하는 매우 쉽고, S3 및 메모리 캐시 작품 out of the box.

캐싱을 처리하기 위해 nginx가 필요하면 질문 제목에 넣으면 답을 더 잘 얻을 수 있다고 생각합니다.

관련 문제