2014-01-22 68 views
0

我有一個Nginx的負載平衡器在幾個服務器的前面。我正在重寫URL以將/ admin開頭的所有內容發送到管理服務器,任何以/ web開頭的web服務器,任何以/ api開頭的任何內容到api服務器。Nginx代理/圖像到/網絡/圖像

我想現在重寫任何以/ image// web/image開頭的東西。

這是到目前爲止我的配置:

upstream api-cluster { 
    ip_hash; 
    server apiserver1.com; 
} 

upstream web-cluster { 
    ip_hash; 
    server webserver1.com; 
} 

upstream admin-cluster { 
    ip_hash; 
    server adminserver1.com; 
} 

server { 
    listen 443 ssl spdy; 
    server_name myloadbalancer.com; 
    keepalive_timeout 70; 

    ssl     on; 
    ssl_certificate  /etc/ssl/foo.crt; 
    ssl_certificate_key /etc/ssl/foo.key; 

    location /api { 
    proxy_pass http://api-cluster; 
    } 

    location /web { 
    proxy_pass http://web-cluster; 
    } 

    location /admin { 
    proxy_pass http://admin-cluster; 
    } 

    location/{ 
    deny all; 
    } 
} 

我有一個形象的API尺寸調整位於webserver1.com/web/image,例如網址:

webserver1.com/web/image/foo.png?width=300&height=150 

如何重寫這樣的:

myloadbalancer.com/image/foo.png?width=300&height=150 

到Web服務器URL?

回答

0

您可以使用重寫將/ image/foo轉換成/ web/image/foo,然後使用proxypass將其發送到webserver1.com。例如:(未經測試)

location /image { 
    rewrite ^/image /web/image break; 
    proxy_pass http://web-cluster; 
}