Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

416
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!