浏览 447
官网:https://github.com/replay/ngx_http_consistent_hash
https://www.nginx.com/resources/wiki/modules/consistent_hash/
下载
文件名:ngx_http_consistent_hash-master.zip
github下载:https://github.com/replay/ngx_http_consistent_hash
unzip ngx_http_consistent_hash-master.zip
编译到Nginx
./configure --add-module=/home/guowenyan/ngx_http_consistent_hash-master
make
make install
worker_processes 1;
events {
worker_connections 1024;
}
http {
upstream www.guowenyan.cn {
consistent_hash $request_uri;
server 106.38.193.183:80;
server 106.38.193.182:80;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://www.guowenyan.cn;
}
}
2.1 发送URL请求
多次发送不同的URL请求。
curl -x 127.0.0.1:80 http://www.guowenyan.cn/1.txt -v
2.2 抓包查看upstream到的地址
sudo tcpdump -i any tcp port 80 and host 106.38.193.183or106.38.193.182
会发现同一个URL,总是回同一个upstream的IP地址。
按点赞数排序
按时间排序