dahlsailrunner / docker-fundamentals

49 stars 67 forks source link

Nginx Issue #9

Closed AhmedBoody closed 2 years ago

AhmedBoody commented 2 years ago

Hi Erik, thanks for the great course, one of the bests on Pluralsight in my view. I try to follow it carefully to develop my own project and there is still one problem I cannot solve. When running project from docker-compose & past URL "http://id-local.globomantics.com:5200" it doesn't work & display a message "This page isn’t working"

Docker Compose :

version: '3.4'

services:
  reverseproxy:
    build:
      context: .
      dockerfile: nginx/nginx.Dockerfile
    depends_on:
      - globomantics.identityserver
    ports:
      - "5200:5100"

  globomantics.identityserver:
    image: ${DOCKER_REGISTRY-}globomanticsidentityserver
    build:
      context: .
      dockerfile: Globomantics.IdentityServer/Dockerfile
    environment:
      - ASPNETCORE_URLS=http://*:5000
    ports:
      - "5000:5000"

nginx.local.conf:

## learn more about nginx reverse proxy configuration here:
## https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/
worker_processes 1;
events { worker_connections 1024; }

http {
    sendfile on;
    large_client_header_buffers 4 32k;

    upstream identity {
        server globomantics.identityserver:5000;
    }

    server {        
        listen 5001;

        server_name id-local.globomantics.com;        

        location / {
            proxy_pass         http://identity;
            proxy_redirect     off;
            proxy_http_version 1.1;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header   Upgrade $http_upgrade;
            proxy_set_header   Connection keep-alive;
            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;
            proxy_set_header   X-Forwarded-Host $server_name;
            proxy_buffer_size           128k;
            proxy_buffers               4 256k;
            proxy_busy_buffers_size     256k;
        }
    }   
}

hosts

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost

127.0.0.1 id-local.globomantics.com

# BEGIN section for OpenVPN Client SSL sites
127.94.0.1  client.openvpn.net
# END section for OpenVPN Client SSL sites
# Added by Docker Desktop
169.254.11.87 host.docker.internal
169.254.11.87 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section

image

dahlsailrunner commented 2 years ago

Hi Ahmed - Thanks for the kind words. I think the problem is that your nginx service and nginx conf file don't agree with one another. In your compose file you have 5200:5100 as the port mapping, but then in the nginx conf file you have listen 5001. The 5100 and 5001 values should be the same. I suspect that will do the trick. Let me know how it goes.

AhmedBoody commented 2 years ago

@dahlsailrunner Thanks for your quick response, I was shocked when I saw ports were not the same,as usual, the bug in front of our eyes but we go beyond it 😄