Please Help With Memcached Setup

Dayo nginx-forum at nginx.us
Mon Aug 9 17:43:05 MSD 2010


Hi

I am running Nginx 0.7.67 with the Memc and Echo 3rd party modules in
trying to follow
http://agentzh.org/misc/slides/nginx-conf-scripting/nginx-conf-scripting.html#35.

I want to serve some static files from memcached and am trying a self
updating setup as in the following pseudocode:
[code]
if request for specified files {
	if in memcache {
		serve from memcache
	} else {
		try to put into memcache
		try to serve from memcache
		if unable to serve from memcache {
			proxy to apache
		}
	}
}
[/code]

I will actually prefer to do this...:
[code]
if request for specified files {
	if in memcache {
		serve from memcache
	} else {
		try to put into memcache
		try to serve from memcache
		if unable to serve from memcache {
			[b]try to serve from disk[/b]
		}
		if unable to serve from memcache {
			proxy to apache
		}
	}
}
[/code]
...but started to get too complicated and I can get to that after I
manage to get it working in the first place

The relevant portion of my conf file is...:
[code]
location ~* ^.+\.(jpe?g|gif|png|css|js|ico|swf|dat|xml)$ {
	set $memc_cmd 'get';
	set $memc_key '$scheme://$host$request_uri';
	memc_pass 127.0.0.1:11211;
	add_header X-Memc-Flags $memc_flags;
	error_page 404 = @add-and-retry;
	error_page 502 = @fallback;
	log_not_found  off;
	access_log /dev/null main;
}
location @add-and-retry {
	echo_location
/memc?cmd=add&key='$scheme://$host$request_uri'&val=$document_root$uri&exptime=0;
	echo_location /memc?cmd=get&key='$scheme://$host$request_uri';
}
location /memc {
	internal;
	set $memc_cmd $arg_cmd;
	set $memc_key $arg_key;
	set $memc_value $arg_val;
	set $memc_exptime $arg_exptime;	
	memc_pass 127.0.0.1:11211;
	error_page 404 502 = @fallback;
}
location @fallback {
	log_not_found  off;
	access_log /dev/null main;
	proxy_pass http://127.0.0.1:8080;
	# proxy params
	include /etc/nginx/proxy.default;
}
[/code]
...but these files do not get served at all. I.E. it doesn't even get
passed to apache.

Please help unravel or suggest alternative(s).

Thanks.

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,117833,117833#msg-117833




More information about the nginx mailing list