配置实例五:实现带有URL重写的负载均衡
…
upstream backend
{
server 192.168.1.2:80;
server 192.168.1.3:80;
server 192.168.1.4:80;
}
server
{
listen 80;
server_name www.myweb.name;
index index.html index.htm;
location /file/ {
rewrite ^(/file/.*)/media/(.*)\.*$ $1/mp3/$2.mp3 last;
}
location / {
proxy_pass http://backend;
proxy_set_header Host $host;
…
}
…
}
如果客户端的请求URL为“http://www.myweb.name/file/download/media/1.mp3”时
该虚拟服务器首先使用location file/ {……}块将该URL进行重写为http://www.myweb.name/file/download/mp3/1.mp3,
然后新的URL再由location / {……}块转发到后端的backend服务器组中实现负载均衡。
Last updated
Was this helpful?