작업실

Nginx에 Microcache 설정했습니다.

컨텐츠 정보

  • 12,901 조회
  • 1 댓글
  • 0 추천
  • 목록

본문

오드로이드U2로 서버를 옮겼기 때문에 캐시를 이용하여 최대한 빠르게 하고 싶었습니다.


일단 XCache는 현재 적용했고, (XCache 적용했습니다.)


원래 Alternative PHP Cache (APC) 를 깔아보려고 했습니다만 Zend Optimizer와 충돌이 일어나더라구요.


새로 셋팅하는 것은 무리가 있을 것 같아 최대한 찾아보니 


Nginx 자체적으로 마이크로캐시가 있더군요. ㅎㅎ


http://eureka.ykyuen.info/2013/01/24/nginx-enable-microcaching/


https://www.digitalocean.com/community/articles/how-to-setup-fastcgi-caching-with-nginx-on-your-vps


위에 두 링크를 보고 쉽게 적용하였습니다.


간단하게 


/etc/nginx/cache 폴더를 생성 후


/etc/nginx/sites-available/default에


server { 바로 위에


add_header X-Cache $upstream_cache_status;


를 넣고


server {}


안에 있는


location ~ \.php$ { 여기에


   # Setup var defaults

   set $no_cache "";

   # If non GET/HEAD, don't cache and mark user as uncacheable for 1 second via cookie

   if ($request_method !~ ^(GET|HEAD)$) {

     set $no_cache "1";

   }

   # Drop no cache cookie if need be

   # (for some reason, add_header fails if included in prior if-block)

   if ($no_cache = "1") {

     add_header Set-Cookie "_mcnc=1; Max-Age=2; Path=/";

     add_header X-Microcachable "0";

   }

   # Bypass cache if no-cache cookie is set

   if ($http_cookie ~* "_mcnc") {

     set $no_cache "1";

   }

   if ($request_uri ~* "/(adm/|login.php)")

   {

set $no_cache 1;

   }

   # Bypass cache if flag is set

   fastcgi_no_cache $no_cache;

   fastcgi_cache_bypass $no_cache;

   #Settings

                  fastcgi_cache microcache;

    fastcgi_cache_key $server_name|$request_uri;

    fastcgi_cache_valid 404 30m;

    fastcgi_cache_valid 200 10s;

    fastcgi_max_temp_file_size 1M;

    fastcgi_cache_use_stale updating;

    fastcgi_pass_header Set-Cookie;

    fastcgi_pass_header Cookie;

    fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

    fastcgi_param  PATH_INFO          $fastcgi_path_info;


위 내용을 넣었습니다.


그리고 


/etc/nginx/conf.d에 


microcache.conf 파일을 생성 후


fastcgi_cache_path /etc/nginx/cache/ levels=1:2 keys_zone=microcache:5m max_size=500m;

map $http_cookie $cache_uid {

  default nil; # hommage to Lisp <span class="wp-smiley emoji emoji-smile" title=":)">:)</span>

  ~SESS[[:alnum:]]+=(?<session_id>[[:alnum:]]+) $session_id;

}

map $request_method $no_cache {

  default 1;

  HEAD 0;

  GET 0;

}


위 내용을 넣어줬구요.


그리고 nginx 재시작 후


/etc/nginx/cache폴더에 들어가면




위와 같이 실시간으로 폴더가 생성되면 되는 것 같네요 ^^;;


속도 향상은 미세한 것 같은데... 일단 되고 있는 것 같으니 만족합니다.


저와 똑같지 하지 마시고;; 링크를 보시고 적용하는 것이 좋아보입니다 ㅎㅎ

관련자료

  • 서명
    우성짱의 NAS를 운영하고 있습니다.

    저의 즐거움이 여러분의 즐거움이면 좋겠습니다.

댓글 1 / 1 페이지
전체 157 / 10 페이지
RSS

최근글


새댓글


알림 0