Skip to content

Upstream naming pre-empts proxy-passing to other load-balanced services #1162

@cheald

Description

@cheald

I have a cluster of hosts which run things like:

app.domain.com
microservice1.domain.com

I have nginx-proxy set up so that certain location blocks get proxy_passed to the microservice:

location /service {
    proxy_pass http://microservice1.domain.com:1234/
}

However, this causes nginx to get confused, because the upstream for the microservice is also named microservice1.domain.com, which results in errors like:

[emerg] 34#34: upstream "microservice1.domain.com" may not have port 1234 in /etc/nginx/vhost.d/app.domain.com:9

What I want to do is for that microservice request to resolve DNS and hit my load balancer, which will then get distributed to one of my upstreams running nginx-proxy. What happens is that nginx-proxy instead sees an upstream with that domain name and attempts to proxy to it. You can't proxy_pass to a defined upstream with a port, so it gets confused.

An easy fix would be to suffix upstream naming with some string so they can't be confused with FQDNs, like:

Before

upstream app.domain.com {
  # ...
}

upstream microservice1.domain.com {
  # ...
}

server {
  location /service {
    proxy_pass http://microservice1.domain.com:1234/
  }
  proxy_pass http://app.domain.com/
}

After

upstream app.domain.com-upstream {
  # ...
}

upstream microservice1.domain.com-upstream {
  # ...
}

server {
  location /service {
    proxy_pass http://microservice1.domain.com:1234/
  }
  proxy_pass http://app.domain.com-upstream/
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions