0

I've been trying to teach myself Nginx. Naturally I figured I should use docker. I'm trying to do this with docker for windows. Would eventually move to Linux server. I feel like I'm so close, but I'm stuck on this last issue.

reverseproxy_1  | 2021/07/14 22:37:31 [error] 31#31: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://172.18.0.2:5000/favicon.ico", host: "localhost:4000", referrer: "http://localhost:4000/" 

Anyone have any suggestions? I'm new to this, so it's probably something stupid. I've gone through several tutorials and I really feel like this should work.

version: '3.7'
services:
        web:
            image: 'anatomy-lab2'
            container_name: 'AnatomyLabWeb'
            ports:
                - "5000:80"
            restart: always
        reverseproxy:
            image: nginx:alpine
            volumes:
                - ./nginx.conf:/etc/nginx/nginx.conf:ro
            ports:
                - '4000:4000'
            depends_on:
                - web
            restart: always

user nginx;

events {
    worker_connections 1000;
}
http {
    upstream web-api {
        server web:5000;
    }


    server {
        listen 4000;
        location / {
            proxy_pass http://web-api;
    }
  }
}
λ docker-compose up                                                                                                                                                                                                
Starting AnatomyLabWeb ... done                                                                                                                                                                                    
Starting anatomy-lab_reverseproxy_1 ... done                                                                                                                                                                       
Attaching to AnatomyLabWeb, anatomy-lab_reverseproxy_1                                                                                                                                                             
reverseproxy_1  | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration                                                                                                 
reverseproxy_1  | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/                                                                                                                        
reverseproxy_1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh                                                                                                            
reverseproxy_1  | 10-listen-on-ipv6-by-default.sh: info: IPv6 listen already enabled                                                                                                                               
reverseproxy_1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh                                                                                                                
reverseproxy_1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh                                                                                                                
reverseproxy_1  | /docker-entrypoint.sh: Configuration complete; ready for start up                                                                                                                                
AnatomyLabWeb   | [04:56:26 WRN] Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed
.                                                                                                                                                                                                                  
AnatomyLabWeb   | [04:56:26 INF] User profile is available. Using '/root/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.                                                       
AnatomyLabWeb   | Hosting environment: Production                                                                                                                                                                  
AnatomyLabWeb   | Content root path: /app                                                                                                                                                                          
AnatomyLabWeb   | Now listening on: http://[::]:80                                                                                                                                                                 
AnatomyLabWeb   | Application started. Press Ctrl+C to shut down.                                                                                                                                                  
reverseproxy_1  | 2021/07/15 04:56:33 [error] 23#23: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: , request: "GET / HTTP/1.1", upstream: "http://172.18.
0.2:5000/", host: "localhost:4000"                                                                                                                                                                                 
reverseproxy_1  | 172.18.0.1 - - [15/Jul/2021:04:56:33 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"   
reverseproxy_1  | 2021/07/15 04:56:33 [error] 23#23: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "htt
p://172.18.0.2:5000/favicon.ico", host: "localhost:4000", referrer: "http://localhost:4000/"                                                                                                                       
reverseproxy_1  | 172.18.0.1 - - [15/Jul/2021:04:56:33 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://localhost:4000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome
/91.0.4472.124 Safari/537.36"                                                                                                                                                                                      

I get the web app to work just fine by itself (asp.net/kestrel). But I can't seem to hook it to Nginx.

Any thoughts on this would be great. I've been stuck for quite a bit of time.

1 Answer 1

2

The problem came from

upstream web-api {
    server web:5000;
}

In the dockerized environment the web container listens :80 so you need to change the config like

upstream web-api {
    server web:80;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. I was thinking it had to be the exposed port. But it makes sense that it would be port 80, since containers are on same docker host. I knew it would be something dumb

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.