我尝试用https://github.com/yaoweibin/ngx_http_consistent_hash 这个来实现上面的场景,但是按照ngx_http_upstream_consistent_hash这个配置,没有弄明白到底是在哪里set cache的,总是进入fallback里面由php脚本来set了。这里是配置有问题还是理解错了,貌似http://www.ostools.net/uploads/apidocs/nginx-zh/HttpUpstreamConsistentHash.htm讲的也不是很清楚,请各位指点一下,谢谢了~
配置在下面:
upstream memcached_backend {
consistent_hash $request_uri;
server 192.168.60.4:11222;
server 192.168.60.4:11211;
}
location / {
default_type text/html;
set $memcached_key $request_uri; #这一步似乎是set了memcache的key 但是值是怎么set的?
memcached_pass memcached_backend;
error_page 500 404 405 = @fallback;
}
location @fallback {
root /home/work/;
fastcgi_intercept_errors on;
error_page 404 = @404;
set $script $uri;
set $path_info "";
include /home/service/openresty/nginx/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/work/website/dolphin/app/scripts/follow/testCon.php;
fastcgi_param SCRIPT_NAME $script;
fastcgi_param REQUEST_URI $uri;
fastcgi_pass 127.0.0.1:9000;
}
php脚本$memcache = new Memcache;
$memcache->addServer('192.168.60.4', 11211);
$memcache->addServer('192.168.60.4', 11222);
$memcache->set($_SERVER["REQUEST_URI"], $_SERVER["REQUEST_URI"] . " from memcache");