Nginx on Docker Unable to reach site

Issue

This Content is from Stack Overflow. Question asked by JianYA

I have this docker compose file that I added an nginx section to:

version: '3.4'

services:
  rp:
    image: nginx:latest
    ports:
      - 8120:80
    restart: always
    volumes:
      - ./nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro
    depends_on:
     - sdr_filestore.api

  sdr_filestore.api:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=http://+
    image: ${DOCKER_REGISTRY-}sdrfilestoreapi
    build:
      context: .
      dockerfile: SDR_Filestore.Api/Dockerfile
    networks: 
    - dev
    ports:
    - 59521:80

This is the nginx.conf file:

events {

}
http {

    server {
        listen 80;
        listen [::]:80;

        server_name localhost;
        server_tokens off;
    }

}

When I run docker-compose, it compiles and runs fine. However, when I run http://localhost:8120, I get this error:

This site can’t be reached localhost refused to connect.

I then tried another method which is to just run the command straight from the Nginx website:

docker run –name mynginx1 -p 8120:80 -d nginx

This also runs fine and when I go to http://localhost:8120, I get the nginx page. What did I configure wrong in my first docker compose file?



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?