Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

421
Vistas
Nginx configuration for connecting to external mongodb from docker swarm

I have a docker swarm running 2 python flask services, each one running in a different region, say A, and B. Region A is also running Nginx, which is the main entrypoint to access the services. There is a MongoDB database running in region A, outside of the docker swarm. The python service running in region A can connect to the MongoDB running in region A, but service B cannot connect to the MongoDB from region B. My question is can I configure the Nginx to proxy service B to connect to the MongoDB?

The Nginx locations config for the services is:

location /a {
  proxy_pass https://a-service:5000/;  # running in region A
}

location /b {
  proxy_pass https://b-service:5001/;  # running in region B
}

Where a-service and b-service are the docker swarm container names.

I saw the posts regarding how to setup MongoDB behind Nginx, but my case is the reverse - to access external MongoDB from inside a docker swarm through an Nginx inside the swarm.

(How to setup MongoDB behind Nginx Reverse Proxy)

I understand that I need to have something like this in the nginx.conf:

stream {
    server {
        listen 27020;
        proxy_connect_timeout 5s;
        proxy_timeout 20s;
        proxy_pass    mongodb_host;
    }

    upstream mongodb_host{
        server https://5.150.225.25:27017;
    }
}

However the location of the mongodb host (https://5.150.225.25) is another vm outside of the docker swarm, not a local IP. This results in an error:

nginx: [emerg] invalid host in upstream "https://5.150.225.25:27017" in nginx.conf
over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda