sesispla / docker-nginx-kestrel

A basic ASP.NET Core App, Dockerized and served with NGINX as proxy server.
MIT License
67 stars 25 forks source link

docker network settings #4

Closed dmarlow closed 6 years ago

dmarlow commented 7 years ago

What network settings do you have setup for docker? I tried what you have, but it wouldn't load balance as I would expect. I have nginx setup to serve on port 5100 and my dotnet app on 5000.

In my dotnet app's Dockerfile, I expose 5000 and in nginx.conf:

worker_processes 1;

events { worker_connections 1024; }

http {

    include mime.types; #include the required MIME types
    sendfile on;

    # List of application servers
    upstream api {

        server api1:5000;
        server api2:5000;
        server api3:5000;

    }

    # Configuration for the server
    server {

        # Running port
        listen 5100;        

        # Proxying the connections
        location / {

            proxy_pass         http://api;
            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-Host $server_name;
            proxy_set_header   X-Forwarded-Proto $scheme;   
        }
    }
}

In the logs I have this:

172.22.0.1 - - [01/Nov/2017:17:31:20 +0000] "GET /api/values HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
2017/11/01 17:31:20 [error] 5#5: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.22.0.1, server: , request: "GET /api/values HTTP/1.1", upstream: "http://127.0.0.1:5000/api/values", host: "api:5100"

I suspect that the bridged mode networking is causing some issues here.

sesispla commented 6 years ago

Hi @dmarlow,

Please have a look to nginx.conf.

Since I am running with PROD configuration, I put port 80 in for kestrel upsetting configuration. Then, nginx is listening on both 80 and 443 ports (80 forwards to 443).

Also, note that I am using a server_name to tell nginx which URL Hostname identifies this application.