Nginx代理/image到/web/image
我在两台服务器前面有一个Nginx负载平衡器。我正在重写URL,以便将以/admin开头的所有内容发送到管理服务器,将以/web开头的所有内容发送到web服务器,将以/api开头的所有内容发送到api服务器 现在,我想将以/image开头的任何内容重写为/web/image 以下是我目前的配置:Nginx代理/image到/web/image,nginx,Nginx,我在两台服务器前面有一个Nginx负载平衡器。我正在重写URL,以便将以/admin开头的所有内容发送到管理服务器,将以/web开头的所有内容发送到web服务器,将以/api开头的所有内容发送到api服务器 现在,我想将以/image开头的任何内容重写为/web/image 以下是我目前的配置: upstream api-cluster { ip_hash; server apiserver1.com; } upstream web-cluster { ip_hash; ser
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?您可以使用重写将/image/foo转换为/web/image/foo,然后使用proxypass将其发送到webserver1.com。类似:(未经测试)
location /image {
rewrite ^/image /web/image break;
proxy_pass http://web-cluster;
}