Nginx将某个位置redirect到单独的服务器

我正尝试将我们的应用程序服务器与我们的网站库存储分开。 我在xxx.xxx.xxx.1和图库服务器上有一个应用程序服务器xxx.xxx.xxx.2上的所有图像。 现在我想这样做,所以每次请求进入到服务器的* .jpeg结尾和/或www.domain.com/uploads开始,将被redirect到www.gallerydomain.com。

我检查了第二台服务器,它工作得很好。

现在,我试着做的第一台服务器上:

location /uploads { proxy_pass http://www.gallerydomain.com; } 

但似乎并不奏效。

Any1对Nginx的这种情况有什么经验? 或者有人能指出我的正确方向? 非常感激。

对不起,我上面没有看到你的评论。 要在客户端进行redirect,这可能很有用:

 server { server_name domain.com; ... rewrite ^/uploads/(.*)$ http://www.gallerydomain.com/$1 permanent; rewrite ^/(.*)\.jpg$ http://www.gallerydomain.com/$1.jpg permanent; ... } 

Nginx会在每个与重写模式匹配的请求上返回“HTTP 301 Moved permanent”响应。 这样浏览器根据“Location:”HTTP响应头的内容redirect到新的位置(并且知道)。

您可以通过在位置块中使用正则expression式来解决此问题:

 location ~ ^/uploads/|\.jpg$ { proxy_pass http://www.gallerydomain.com; }