ecs-nginx-reverse-proxy icon indicating copy to clipboard operation
ecs-nginx-reverse-proxy copied to clipboard

nginx: [emerg] host not found in upstream "app" in /etc/nginx/nginx.conf:24

Open cmthomps opened this issue 4 years ago • 7 comments

When I attempt to deploy this, the nginx container fails and stops with an error "nginx: [emerg] host not found in upstream "app" in /etc/nginx/nginx.conf:24". It seems like the internal name resolution doesn't work. I was having a similar problem with another project and then just tried to deploy this project as is. Has something changed in ECS since this was developed?

Full log:


timestamp message
1609878836789 /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
1609878836789 /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
1609878836792 /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
1609878836795 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
1609878836804 10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
1609878836805 /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
1609878836809 /docker-entrypoint.sh: Configuration complete; ready for start up
1609878836823 2021/01/05 20:33:56 [emerg] 1#1: host not found in upstream "app" in /etc/nginx/nginx.conf:24
1609878836823 nginx: [emerg] host not found in upstream "app" in /etc/nginx/nginx.conf:24

cmthomps avatar Jan 05 '21 21:01 cmthomps

I'm also facing a similar issue trying this approach, it looks like the host name can't be resolved with this setup anymore.

...myapp could not be resolved (3: Host not found)...

dfelski avatar Feb 03 '21 18:02 dfelski

In my case, the hostname lookup failed because the ECS task is not up yet. Maybe you could try adding this to your nginx section:

depends_on:
      - app

Btw from the official docker compose documentation, service.links is not (no longer?) implemented.

htchaan avatar Dec 08 '21 11:12 htchaan

try adding this :

    web:
        image: nginx:alpine
        working_dir: /app
        restart: unless-stopped
        volumes:
            - .:/app
            - ./.docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
        port:
           - ...
        depends_on:
            - php-fpm
        networks:
            - nginx_net

    app:
        image: php:7-fpm
        working_dir: /app
        restart: unless-stopped
        volumes:
            - .:/app
            - ...
        environment:
            ....
        networks:
            - nginx_net
            

oussaka avatar Jun 09 '22 21:06 oussaka

Had the same error in a different project. Once I switched from nginx:1.23.3-alpine to nginx:1.23.3 it worked without any further adjustments. Not sure why the alpine image wasn't able to find the host, though.

netbrothers-tr avatar Feb 24 '23 13:02 netbrothers-tr

After I changed from "alpine" to "1.22.0-alpine" (didn't check on newer versions), it's working.

dzung1nguyen avatar Mar 17 '23 08:03 dzung1nguyen

Using nginx:1.25.2 but still facing with this issue.

2023/08/23 12:01:33 [emerg] 1#1: host not found in upstream "$server_two" in /etc/nginx/conf.d/alb.conf:32 nginx: [emerg] host not found in upstream "$server_two" in /etc/nginx/conf.d/alb.conf:32

my environment is: Win 10 WSL2 Docker

docker-compose.yml

version: "3" services: app: image: nginx:1.25.2 container_name: "load_balancer_nginx" ports: - "80:80" - "8000:8000" volumes: &appvolumes - ../src/:/var/www/html:rw - ../nginx/nginx.conf:/etc/nginx/nginx.conf - ../nginx/default.conf:/etc/nginx/conf.d/default.conf - ../nginx/alb.conf:/etc/nginx/conf.d/alb.conf # Application Load Balance

nginx -T

` nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

configuration file /etc/nginx/nginx.conf:

events {}

http { include /etc/nginx/conf.d/*.conf; }

configuration file /etc/nginx/conf.d/alb.conf:

server {
    listen 8000;
    server_name server.one;
    root /var/www/html/server.one/;
    charset utf-8;

    index index.html;
    location / {
        try_files $uri $uri/ =404;
    }
}

server {
    listen 8088;
    server_name server.two;
    root /var/www/html/server.two/;
    charset utf-8;

    index index.html;
    location / {
        try_files $uri $uri/ =404;
    }
}

map $scheme $server_two {
  default server.two:8088;
}

upstream all {
    keepalive 20;
    server server.one:8000 fail_timeout=999s max_fails=999999;
    #server $server_two;
}

server {
    listen 80;

    server_name magento_alb.loc;

    absolute_redirect off;

    location / {
        set $backend_servers all;
        proxy_pass http://$backend_servers;
        #proxy_pass http://$backend_servers:8080;

        #proxy_pass http://all/;

        proxy_pass_request_headers on;
        proxy_set_header Host $host;
        #proxy_set_header Host magento_alb.loc;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;

        proxy_redirect off;
        proxy_intercept_errors on;
        proxy_cache off;
    }
}

configuration file /etc/nginx/conf.d/default.conf:

#nothing. just to rewrite the existing one. `

Could someone help me to figure this out ?

xdoctordog avatar Aug 23 '23 12:08 xdoctordog

I'm getting the same error on docker hub, can you help me with this? nginx: [emerg] host not found in upstream "openems-ui" in /etc/nginx/nginx.conf:31

These are my nginx.conf configration file

worker_processes 1;

events { worker_connections 1024; }

http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 5;

    server {
            #listen 80;
            #server_name localhost 127.0.0.1;

            listen 80;
            root /usr/share/nginx/html/;
            rewrite_log on;

            location / {
                    rewrite ^ /m/$args last;
            }

            location /m/ {
                    index index.html;
                    try_files $uri$args $uri$args/ /index.html;
            }

            location / {
            proxy_pass          http://openems-ui:80;
            proxy_set_header    X-Forwarded-For $remote_addr;
        }

        location /backend {
            proxy_pass          http://openems-backend:8079/;
            proxy_set_header    X-Forwarded-For $remote_addr;
        }

        location /edge {
            proxy_pass          http://openems-edge:8080/;
            proxy_set_header    X-Forwarded-For $remote_addr;
        }
        location /ui-edge {
            proxy_pass          http://ui-edge:8082/;
            proxy_set_header    X-Forwarded-For $remote_addr;
        }
        location /ui-backend {
            proxy_pass          http://ui-backend:8082/;
            proxy_set_header    X-Forwarded-For $remote_addr;
        }

            
    }

}

Docker file

FROM --platform=$BUILDPLATFORM alpine:latest AS ui_builder

RUN apk update && apk upgrade

RUN apk add --no-cache
npm
nodejs

RUN npm install -g @angular/cli

FROM --platform=$BUILDPLATFORM ui_builder AS build_ui

ARG UI_VERSION

COPY ./ /src

WORKDIR /src/ui RUN npm install

FROM ghcr.io/linuxserver/baseimage-alpine:edge AS ui_base

RUN apk update && apk upgrade

RUN apk add --no-cache
nginx
openssl
npm
nodejs

RUN npm install -g @angular/cli

FROM ui_base

RUN mkdir -p /etc/nginx/site-templates /var/log/nginx /var/www/html/openems

COPY --from=build_ui /src/ui/ /opt/ui/src COPY tools/docker/openems-ui/root/ /

COPY tools/docker/openems-ui/nginx.conf /etc/nginx/nginx.conf

COPY --chown=root:root tools/docker/openems-ui/nginx.conf /etc/nginx/nginx.conf

VOLUME /etc/nginx VOLUME /var/log/nginx

ARG HOST ARG WEBSOCKET_PORT

ENV TYPE edge ENV REST_API_PORT 8084

EXPOSE 80 443

yml file

name: Build OpenEMS Docker Image

on: push: paths: - .github/workflows/openems-ui.yml - 'workflow/**'

jobs: docker: runs-on: ubuntu-latest strategy: fail-fast: false matrix: image: [openems-edge, openems-backend, openems-ui, ui-backend, ui-edge] include: - image: openems-edge dockerfile: tools/docker/openems-edge/Dockerfile repo: manoj1210/openems-edge - image: openems-backend dockerfile: tools/docker/openems-backend/Dockerfile repo: manoj1210/openems-backend - image: openems-ui dockerfile: tools/docker/openems-ui/Dockerfile repo: manoj1210/openems-ui - image: ui-backend dockerfile: tools/docker/ui-backend/Dockerfile repo: manoj1210/ui-backend - image: ui-edge dockerfile: tools/docker/ui-edge/Dockerfile repo: manoj1210/ui-edge

steps:
  - name: Checkout
    uses: actions/checkout@v4

  - name: Set up QEMU
    uses: docker/setup-qemu-action@v3

  - name: Set up Docker Buildx
    uses: docker/setup-buildx-action@v3

  - name: Get cleaned branch name
    id: clean_name
    run: |
      REF_NAME=$(echo "${{ github.ref }}" | sed -e 's/refs\/heads\///' -e 's/refs\/tags\///' -e 's/release\/v//')
      echo "branch=${REF_NAME}-test" >> "$GITHUB_OUTPUT"

  - name: Login to Docker Hub
    uses: docker/login-action@v3
    with:
      username: ${{ secrets.DOCKERHUB_USERNAME }}
      password: ${{ secrets.DOCKERHUB_TOKEN }}

  - name: Login to GitHub Container Registry
    uses: docker/login-action@v3
    with:
      registry: ghcr.io
      username: ${{ github.actor }}
      password: ${{ secrets.GITHUB_TOKEN }}

  - name: Extract metadata (tags, labels) for Docker
    id: meta
    uses: docker/metadata-action@v5
    with:
      images: |
        ${{ matrix.repo }}
      labels: |
        org.opencontainers.image.authors=manoj1210
        org.opencontainers.image.title=manoj1210 ${{ matrix.image }}
        org.opencontainers.image.vendor=manoj1210

        
  - name: Build and push Docker images
    uses: docker/build-push-action@v5
    with:
      file: ${{ matrix.dockerfile }}
      platforms: linux/amd64, linux/arm64
      push: true
      tags: ${{ steps.meta.outputs.tags }}
      labels: ${{ steps.meta.outputs.labels }}

#reverse-proxy:

runs-on: ubuntu-latest

needs: docker

steps:

- name: Checkout repository

uses: actions/checkout@v2

- name: Build and run reverse proxy container

run: |

docker build -t reverse-proxy -f tools/docker/reverse-proxy/Dockerfile .

#s docker run -d -p 80:80 reverse-proxy

manojniit avatar Feb 28 '24 08:02 manojniit