|
#V3 is for 64bit OS,Linux or FreeBSD. #64 is for the 64-bit platform Install
tar -vxzf ncache-3.0_64.tar.gz
mv -fR ncache nginx-0.6.34/src/http/modules/
./configure --add-module=src/http/modules/ncache/
make
make install
Configvi your nginx config file "/usr/local/nginx/conf/nginx.conf"
user www www;
worker_processes 4;
worker_rlimit_nofile 20480;
error_log logs/error.log;
events
{
use epoll;
worker_connections 81920;
}
http
{
keepalive_timeout 10;
ncache_max_size 24;
proxy_buffering off;
ncache_dir /data1/cache_file 60;#the file for storage,60G
ncache_dir /data2/cache_file 60;
hash_index_dir /data1/ncache_index;#v3.1,you need to define the index file position
auto_delete_file on;#enable the auto delete file
ncache_ignore_client_no_cache on;
upstream backend
{
server 10.0.0.1;
}
sendfile on;
send_timeout 10;
client_header_timeout 10;
tcp_nodelay on;
log_format main '$proxy_add_x_forwarded_for - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" $remote_addr';
include "mime.types";
default_type text/html;
server
{
server_name .blog.sina.com.cn;
listen *:80;
set $xvia "blog.sina.com.cn";
set $proxy_add_agent "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; NginxCache)";
access_log logs/blog.sina.com.cn-access_log main;
location /
{
if ($request_method ~ "PURGE")
{
rewrite (.*) /PURGE$1 last;
}
ncache_http_cache;
error_page 404 = /fetch$request_uri;
add_header Sina-Cache $xvia;
}
location /ncache_state
{
ncache_state;
}
location /fetch
{
internal;
proxy_pass http://backend;
add_header Sina-Cache $xvia;
proxy_hide_header User-Agent;
proxy_set_header User-Agent $proxy_add_agent;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /PURGE/
{
access_log logs/purge.blog.sina.com.cn-access_log main;
internal;
allow 10.55.37.0/24;
allow 10.69.3.0/24;
allow 10.49.10.0/24;
deny all;
ncache_purge;
}
}
}
Run/usr/local/nginx/sbin/nginx Stopkillall -9 nginx Cleanthe clean shell:
#! /bin/sh
kill -9 `ps auwx|grep nginx|awk '{print $2}'`
killall -9 nginx
rm ../logs/ncache_index
echo "" > ../logs/error.log
rm /data0/ncache_file
rm /data1/ncache_file
rm /data2/ncache_file
rm /data3/ncache_file
Statecurl "http://127.0.0.1/ncache_state" Backend Setyou 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.
you must have the "content-len" header in the backend and send it to the ncache.
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.
about the auto delete files process,it deletes the inactive cached data,about 20% of the total data.it runs at 2:00 every day.
|
"killall -9 nginx"
-9? Seriously?
yes
I installed ncache V3 on a server with Centos 4.6 64bit,after running, I tailed the error log, and found a lot error message like this:
2009/01/24 09:59:09 error? 3635#0: 822 cache_from_mem error: file size is not equal the storage size while sending response to client, client: 222.71.103.247, server: abb.abb.cn, request: "GET /photo/2008/10/16/10419149_19580774.jpg HTTP/1.1", host: "abb.abb.cn", referrer: "http://abb.abb.cn/24045.shtml"
so,can u tell me what's the matter? thx
shinepf,
Why such harsh measures? Nginx supports nicer shutdown via SIGQUIT or SIGTERM. Is there any reason not to use them?
I think kill -9 is for that nginx cannot release its port normally with ncache. such as: emerg? 26462#0: bind() to 0.0.0.0:80 failed (98: Address already in use) notice? 26462#0: try again to bind() after 500ms
I have some questions about ncache
What does ncache_max_size 24; do? and is there any minimum size of ncache_dir? Is it possible to set how much ram memory that is used by ncache? Will use ncache to cache static files preferably in ram memory on the frontend servers if possible. Thanks
2009/03/09 16:35:53 emerg? 15577#0: ncache_index_fd < 0 2009/03/09 16:35:53 emerg? 15577#0: ncache_http_proxy_shm_hash_init error whit nginx-0.7.40 and ncache-3.1_64 @ debian 2.6.26-1-amd64.
Have any idea to resolve ?
this problem is because the index file could not be build
please check your accessbility, maybe use root can resolve it
user root dont help :( any other suggestion ?
do u have enough disk space to have the hash_index file ? about 1g?
i have about 100G free space :( so i dont know what missing. Can i help with compile options?
how can I have it cache only media files?
hi.
a little question: if multiple requests for resource will come in simultaneouly, will it do a request to upstream for each such request or will wait until one request completes and send results for everyone?
i'm thinking about using ncache as a reverse proxy and would like it to cache resource for some small time, like seconds. i wonder if it will work fine in this case.
thanks.
It cannot be compiled for Nginx 0.8.1, Ubuntu 0.8.4 (amd64x2)
You said " you must have the "content-len" header in the backend and send it to the ncache. " I use lighttpd as the backend web server serving html files,and ncache only receive max-age header and no content-length is available ( Transfer-Encoding: chunked ) and still it caches. Why?
I can't compile ncache-2.3 for nginx-0.7.59 on 32bit-cpu too:
I objs -I src/http -I src/http/modules -I src/mail \ -o objs/addon/ncache-2.3/ncache_http_get_cache_module.o \ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c src/http/modules/ncache-2.3/ncache_http_get_cache_module.c: In function ‘ncache_http_proxy_get_request_path’: src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:531: error: ‘ngx_http_cache_t’ has no member named ‘path’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:533: error: ‘ngx_http_cache_t’ has no member named ‘path’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:534: error: ‘ngx_http_cache_t’ has no member named ‘path’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:543: error: ‘ngx_http_cache_t’ has no member named ‘path’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:545: error: ‘ngx_http_cache_t’ has no member named ‘path’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:546: error: ‘ngx_http_cache_t’ has no member named ‘path’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:558: error: ‘ngx_http_cache_t’ has no member named ‘path’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:563: error: ‘ngx_http_cache_t’ has no member named ‘path’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:567: error: ‘ngx_http_cache_t’ has no member named ‘path’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c: In function ‘ncache_http_proxy_get_md5’: src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:576: error: ‘ngx_http_cache_t’ has no member named ‘path’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:576: error: ‘ngx_http_cache_t’ has no member named ‘path’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:577: error: ‘ngx_http_cache_t’ has no member named ‘md5’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c: In function ‘ncache_http_proxy_get_hash_index’: src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:587: error: ‘ngx_http_cache_t’ has no member named ‘md5’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c: In function ‘ncache_http_proxy_get_path’: src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:986: error: ‘ngx_http_cache_t’ has no member named ‘md5’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c: In function ‘ncache_http_proxy_shm_is_timeout’: src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:1242: error: ‘ngx_http_cache_t’ has no member named ‘crc’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:1245: error: ‘ngx_http_cache_t’ has no member named ‘crc’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:1246: error: ‘ngx_http_cache_t’ has no member named ‘crc’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:1249: error: ‘ngx_http_cache_t’ has no member named ‘crc’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:1251: error: ‘ngx_http_cache_t’ has no member named ‘crc’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:1252: error: ‘ngx_http_cache_t’ has no member named ‘crc’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c: In function ‘ncache_http_proxy_set_gzip’: src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:1304: error: ‘ngx_http_cache_t’ has no member named ‘crc’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c: In function ‘ncache_http_get_cache_handler’: src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:1380: error: ‘ngx_http_cache_t’ has no member named ‘crc’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:1391: error: ‘ngx_http_cache_t’ has no member named ‘md5’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:1396: error: ‘ngx_http_cache_t’ has no member named ‘crc’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c: In function ‘ngx_http_upstream_cache_lio_write’: src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:2152: error: ‘ngx_http_cache_t’ has no member named ‘expires’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:2153: error: ‘ngx_http_cache_t’ has no member named ‘crc’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:2154: error: ‘ngx_http_cache_t’ has no member named ‘md5’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c: In function ‘ncache_get_hash_index’: src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:2214: error: ‘ngx_http_cache_t’ has no member named ‘crc’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:2221: error: ‘ngx_http_cache_t’ has no member named ‘md5’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:2224: error: ‘ngx_http_cache_t’ has no member named ‘crc’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c: In function ‘ngx_http_shm_hash_del’: src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:2246: error: ‘ngx_http_cache_t’ has no member named ‘crc’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:2249: error: ‘ngx_http_cache_t’ has no member named ‘crc’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:2251: error: ‘ngx_http_cache_t’ has no member named ‘crc’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c: In function ‘ncache_http_proxy_purge_handler’: src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:2302: error: ‘ngx_http_cache_t’ has no member named ‘md5’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:2304: error: ‘ngx_http_cache_t’ has no member named ‘crc’ src/http/modules/ncache-2.3/ncache_http_get_cache_module.c: In function ‘ngx_http_upstream_cache_header_filter’: src/http/modules/ncache-2.3/ncache_http_get_cache_module.c:2535: error: ‘ngx_http_cache_t’ has no member named ‘expires’ make[1]: *** [objs/addon/ncache-2.3/ncache_http_get_cache_module.o] Error 1 make[1]: Leaving directory `/usr/local/src/nginx-0.7.59' make: *** [build] Error 2Please Help!
:-(
Seems to be a problem with the 0.7.x series. Had the same make errors myself, tried with the latest 0.6.x and she compiled just fine.
Ubuntu Hardy Heron 8.04 :
Does not compile nginx-0.7.61 with ncache-3.1:
Does not compile nginx-0.8.4 with ncache-3.1:
Does compile nginx-0.6.38 with ncache-3.1:
Hi, i have configured the ncache as shown above.
But i get the following error: 2009/08/06 10:43:37 error? 11082#0: 35 no space on the disk: used pages = 0,total pages =15697968,need nums = 4503599627370496,used_file_num = 1 while reading response header from upstream, ... on the Disk 90 GB available.
Can anyone give me a hint?
I have this error:
Starting nginx: 2009/09/16 07:13:09 emerg? 27118#0: "ncache_dir" directive mmap failure in /etc/nginx/nginx.conf:64
What it's wrong with a ncache_dir directive?