一、nginx安装第三方模块 (以memcache负载均衡为例)
下载ngx_http_php_memcache_standard_balancer-master
解压到path/ngx_module
编译配置 ./configure --prefix=/xxx/xxx --add_module=/path/ngx_module
编译安装 make&&make install
二、nginx&memcached
#简单取模转发
upstream memserver {hash_key $request_uri;server 127.0.0.1:11211;server 127.0.0.1:11212;#upstream 中的地址不能用localhost
}
location / {set $memcached_key $uri;memcached_pass memserver;#error_page 404 /callback.phperror_page 404 =200 /callback.php#状态码为404不利于SEO,把404改写为200index index.php index.html index.htm
}
三、使用一致性哈希做memcached均衡
安装第三方模块 ngx_http_consistent_hash-master(http://wiki.nginx.org/NginxHt... )
配置nginx.conf
upstream memserver {consistent_hash $request_uri;server 127.0.0.1:11211;server 127.0.0.1:11212;
}
配置 php.ini memcache.hash_strategy = consistent