[英]Nginx proxy_pass failover to multiple upstream servers
I'm having a hard time finding a solution for nginx proxy_pass failover setup. 我很难找到nginx proxy_pass故障转移设置的解决方案。
I need to proxy certain locations to backend server URL's - 我需要代理某些位置到后端服务器URL-
location /Data {
proxy_pass https://backend1.example.com/site1-url;
proxy_set_header X_HOST $host;
}
location /Photos {
proxy_pass https://backend1.example.com/site2-url;
proxy_set_header X_HOST $host;
}
It works as expected, but I need nginx to failover to another server. 它可以按预期工作,但是我需要nginx才能故障转移到另一台服务器。 So the obvious thing would be to use upstream: 因此,显而易见的事情是使用上游:
upstream servers {
server backend1.example.com;
server backend2.example.com backup;
{
location /Data {
proxy_pass https://servers/site1-url;
proxy_set_header X_HOST $host;
}
location /Photos {
proxy_pass https://servers/site2-url;
proxy_set_header X_HOST $host;
}
..., but this doesn't work. ...,但这不起作用。 Nginx doesn't understand that the proxy_pass contains upstream. Nginx不理解proxy_pass包含上游。
Is there an elegant way to do this? 有没有一种优雅的方法可以做到这一点?
Use proxy_pass https://servers
and use a rewrite to go to site1-url and site2-url: 使用proxy_pass https://servers
并使用重写来转到site1-url和site2-url:
location /Data {
rewrite ^ /site1-url/$request_uri? break;
proxy_pass https://servers;
proxy_set_header X_HOST $host;
}
location /Photos {
rewrite ^ /site2-url/$request_uri? break;
proxy_pass https://servers;
proxy_set_header X_HOST $host;
}
WARNING : I've not tested this configuration. 警告 :我尚未测试此配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.