skip to Main Content

Getting the following nginx error when hitting localhost on the host

cron-job-server-nginx-1            | 172.18.0.2 - - [29/Mar/2023:09:56:23 +0000] "GET / HTTP/1.1" 502 157 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/111.0"
cron-job-server-nginx-1            | 2023/03/29 09:56:23 [error] 22#22: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.2, server: , request: "GET / HTTP/1.1", 

I’ve tried setting environment variable ASPNETCORE_URLS to http://+:5000 but it doesn’t change anything.

There is an interesting output line from ASP.NET, but shouldn’t affect IPV4?:

cron-job-server-cron-job-server-1  |       Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'.

docker-compose.yml:

version: '3.7'

services:
    nginx:
        image: nginx:stable-alpine
        volumes:
            - ./nginx.conf:/etc/nginx/nginx.conf
        ports:
            - 80:80
            - 443:443
        restart: always
        depends_on:
            - cron-job-server
    cron-job-server:
        build:
            dockerfile: Dockerfile
        expose:
            - 5000

Dockerfile (ASP.NET):

FROM mcr.microsoft.com/dotnet/sdk:7.0
COPY . ./application
WORKDIR /application
RUN apt-get update
RUN apt-get install mariadb-client -y
RUN cp RaspCronJobServer/appsettings.json appsettings.json
RUN dotnet build
ENTRYPOINT ["dotnet", "run", "--project=RaspCronJobServer"]

NGINX config:

user nginx;

events {
    worker_connections 1000;
}
http {
  server {
    listen 80;
    location / {
      proxy_pass http://cron-job-server-cron-job-server-1:5000;
    }
  }
}

2

Answers


  1. Chosen as BEST ANSWER

    Added this to appsettings.json which fixed it:

    "Kestrel": {
      "EndPoints": {
        "Http": {
          "Url": "http://0.0.0.0:5000"
        }
      }
    },
    

  2. In order to an Environment variable to take effect you need to move specify it inside a Dockerfile, e.g.:

    FROM base AS final
    WORKDIR /app
    ENV ASPNETCORE_URLS=http://+:5000
    COPY --from=publish /app/publish .
    ENTRYPOINT ["dotnet", "MyApp.dll"]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search