我有几个服务器地址,如cdn1.website.com,cdn2.website.com,cdn3.website.com.他们每个人都持有simillar文件.
最佳答案
您可以尝试使用split clients模块:
原文链接:https://www.f2er.com/nginx/434817.htmlhttp {
# Split clients (approximately) equally based on
# client ip address
split_clients $remote_addr $cdn_host {
33% cdn1;
33% cdn2;
- cdn3;
}
server {
server_name example.com;
# Use the variable defined by the split_clients block to determine
# the rewritten hostname for requests beginning with /images/
location /images/ {
rewrite ^ http://$cdn_host.example.com$request_uri? permanent;
}
}
}