nginx负载均衡配置(consistent_hash、error_page)进阶
时间:2014-06-28 02:06 来源:未知 作者:admin
采用consistent方式进行url_hash负载均衡。
重新编译nginx:
复制代码代码如下:
wget http://download.github.com/replay-ngx_http_consistent_hash-77b6940.tar.gz
tar zxvf replay-ngx_http_consistent_hash-77b6940.tar.gz
cd nginx-0.7.65
./configure --prefix=/home/nginx --with-pcre=/tmp/pcre-8.01 --with-http_stub_status_module --with-http_ssl_module --without-http_rewrite_module --add-module=/tmp/nginx_upstream_hash-0.3 --add-module=/tmp/replay-ngx_http_consistent_hash-77b6940
make && make install
修改配置文件:
复制代码代码如下:
upstream images6.static.com {
server 11.11.11.12:80;
server 11.11.11.13:80;
consistent_hash $request_uri;
}
访问测试正常。
error_page配置备份:
复制代码代码如下:
upstream backup {
server 11.11.11.14:80;
}
error_page 404 500 502 503 504 =200 @fetch;
location @fetch {
proxy_pass http://backup;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
(责任编辑:IT)
采用consistent方式进行url_hash负载均衡。
重新编译nginx:
复制代码代码如下:
wget http://download.github.com/replay-ngx_http_consistent_hash-77b6940.tar.gz
tar zxvf replay-ngx_http_consistent_hash-77b6940.tar.gz cd nginx-0.7.65 ./configure --prefix=/home/nginx --with-pcre=/tmp/pcre-8.01 --with-http_stub_status_module --with-http_ssl_module --without-http_rewrite_module --add-module=/tmp/nginx_upstream_hash-0.3 --add-module=/tmp/replay-ngx_http_consistent_hash-77b6940 make && make install
修改配置文件:
复制代码代码如下:
upstream images6.static.com {
server 11.11.11.12:80; server 11.11.11.13:80; consistent_hash $request_uri; } 访问测试正常。
error_page配置备份:
复制代码代码如下:
upstream backup {
error_page 404 500 502 503 504 =200 @fetch; (责任编辑:IT) |