My favorites | Sign in
Project Logo
             
Search
for
Updated May 07, 2008 by shinepf
Labels: Featured, Phase-QA, Phase-Deploy
HowToUseNCache  

How to use ncache

edit your config file at
      {install_prefix}/conf/ncache.conf
run the "mkdir_ngx_cache.sh" to make cache dir:
      {install_prefix}/bin/mkdir_ngx_cache.sh {install_prefix}/conf/ncache.conf
note:only support linux

  user  www www;

  worker_processes 4;
  
  #ulimit -n 20480
  worker_rlimit_nofile 20480;

  events
  {
    worker_connections  10240;
  }


  http
  {
    sendfile        on;

    keepalive_timeout  65;

    #here to set the free list max size 2 Power 24 about 30,000,000
    #in 1.2 or 1.1 it is 25
    cache_max_size 24;
    
    #the new config in v1.3 to set proxy big file buffer null
    proxy_buffering off;



    upstream backend
    {
      server 10.1.1.1;
      server 10.1.1.2;

      #just support 256,128,and 64
      #you must end path with '/' 
      cachedir /data0/ 128 128;
      cachedir /data1/ 64 64;
    }


    server
    {
      listen       80;

      set $purge_uri $request_uri;

      location /
      {
        if ($request_method ~ "PURGE")
        {
          rewrite (.*) /PURGE$1 last;
        }                                                                                         
        proxy_pass http://backend;
        
        #here you can ignore any client use "Cache-Control:no-cache" headers refresh the cache

        proxy_ignore_client_no_cache on;
      }                
      
      #allow some one who can use http PURGE method delete the caches
      location /PURGE/ 
      {   
        internal;        
        allow   10.1.1.0/24;           
        deny    all;
        purge;  
      }
      
      #use "http://{serverip}/status_infos" watch nginx services status
      location /status_infos
      {
        access_log      off;
        stub_status     on;
      }     
    }  
  }
you must add the http header Cache-Control: max-age=*** to the backend server which you want to be cached, ortherwise, ncache will not cache it forever.
if you set max-age < 1 minute ncache will set it to 1 minute, and ncache will exact all max-age to minute, so please align it to 60.
run: {install_prefix}/sbin/ncache
kill: kill -9 ps auwx|grep ncache|awk '{print $2}'

Comment by iammecn, Apr 11, 2008

如何设计虚拟主机啊? 好像这一段 " server 10.1.1.1; server 10.1.1.2;" 但我弄了,没有用啊,说我找不到此页

Comment by jxh2ty, Apr 16, 2008

能不能实现 http://wwwtest.zdnet.com.cn/techupdate/2007/0831/481941.shtml 中的功能?给个一个配置实例!

Comment by jxh2ty, Apr 16, 2008

能不能实现 http://wwwtest.zdnet.com.cn/techupdate/2007/0831/481941.shtml 中后台多个WEB服务的功能?给个一个配置实例!

Comment by emmett.shear, Apr 21, 2008

If you fail to have a user and group in the ncache.conf file mkdir_ngx_cache.sh will fail to chown properly.

Comment by Arden.Emily, May 26, 2008
upstream www.iding.com {
server 127.0.0.1:8001; cachedir /backup/ncache/www.iding.com/ 128 128;
}
upstream shop.iding.com {
server 127.0.0.1:8002; cachedir /backup/ncache/shop.iding.com/ 128 128;
}
upstream admin.iding.com {
server 127.0.0.1:8003; cachedir /backup/ncache/admin.iding.com/ 128 128;
}
server {
listen 80; server_name www.iding.com;
  1. harset koi8-r;
  1. ccess_log logs/host.access.log main;
location / {
root /data/webapps/www/www.iding.com; proxy_pass http://www.iding.com; proxy_redirect off; proxy_ignore_client_no_cache on;
}
}
server {
listen 80; server_name shop.iding.com;
  1. harset koi8-r;
  1. ccess_log logs/host.access.log main;
location / {
root /data/webapps/www/shop.iding.com; proxy_pass http://shop.iding.com; proxy_redirect off; proxy_ignore_client_no_cache on;
}
}
server {
listen 80; server_name admin.iding.com;
  1. harset koi8-r;
  1. ccess_log logs/host.access.log main;
location / {
root /data/webapps/www/admin.iding.com; proxy_pass http://admin.iding.com; proxy_redirect off; proxy_ignore_client_no_cache on;
}
}

配置多个Web应用的时候就不行了。

Comment by flyincat, Sep 12, 2008

无法命中啊 time_count:603 request_count:335569 shoot_count:0 disk_writes:0 store_files:0 upstream_count:49 free_index:16777215


Sign in to add a comment
Hosted by Google Code