1

I have an API and a web application that are running in the same docker cluster.

1) Is it best to have one nginx container loadbalancing the two or have two separate nginx containers load balancing each separately?

2) If the former, I tried this:

server {
    listen 80;
    server_name xxy.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name

 xxy.com;

    location / {
        proxy_pass http://web_app:8000;
        proxy_redirect     off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

    }
}


server {
    listen 443 ssl;
    server_name yyyy.com;

    location / {
        proxy_pass http://api_backend:5000;
        proxy_redirect     off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

    }
}

However, I get a 502 nginx gateway error for the api.

And with the latter solution I have had to change the port of one of the api to 444 since when I docker-compose up I get a port 443 is already in use error.

server {
    listen 444 ssl;
    server_name yyyy.com;

    location / {
        proxy_pass http://api_backend:5000;
        proxy_redirect     off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

    }
}

Any ideas or ways that I can go about solving the problem of have two nginx processes on the same server?

Note: My DNS is configured to redirect to the same IP address.

I also tried following this to no avail. Still the same error as above.

  • Looks correct. I would put an nginx configuration to do this: listen to port 80, and then redirect to 433 of the same domain to use the 8080 on backends. Listen again on 433 of another domain if you need it like this to send request to api backend on 5000. If you call it directly it works? Because 502 error means that nginx is being hitted and then the backend does not work. – Federico Galli Jul 19 '17 at 10:08

0 Answers0