我在几台服务器前面有一个Nginx负载均衡器。我正在重写网址,将所有以/admin开头的内容发送到管理服务器,任何以/web开头的内容发送到web服务器,任何以/api开头的内容发送到api服务器。
现在,我想将所有以/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,示例URL:
webserver1.com/web/image/foo.png?width=300&height=150
如何重写此代码:
myloadbalancer.com/image/foo.png?width=300&height=150
到web服务器的URL?
发布于 2014-01-22 19:35:31
您可以使用重写将/image/foo转换为/web/image/foo,然后使用代理将其发送到webserver1.com。类似于:(未测试)
location /image {
rewrite ^/image /web/image break;
proxy_pass http://web-cluster;
}
https://stackoverflow.com/questions/21279857
复制相似问题