NGINX Reverse Proxy + ngx_upstream_resolveMK - Trying to resolve SRV from ECS Service Discovery Route53 Auto Naming NGINX Reverse Proxy + ngx_upstream_resolveMK - Trying to resolve SRV from ECS Service Discovery Route53 Auto Naming nginx nginx

NGINX Reverse Proxy + ngx_upstream_resolveMK - Trying to resolve SRV from ECS Service Discovery Route53 Auto Naming


Nginx has a problem using internal DNS when you want use it in ECS.

I was successful after using HA-Proxy.

It uses the "links" option of Docker, and HA-Proxy support uses /etc/hosts file.

  1. First, use "links" option of Docker and setting "environment variables" (eg. LINK_APP, LINK_PORT).

  2. Second, fill these "environment variables" into haproxy.cfg.

Also, I recommend you use "dynamic port mapping" to ALB. it makes more flexible works.

taskdef.json:

{    "executionRoleArn": "arn:aws:iam::<AWS_ACCOUNT_ID>:role/<APP_NAME>_ecsTaskExecutionRole",    "containerDefinitions": [      {        "name": "<APP_NAME>-rp",        "image": "gnokoheat/ecs-reverse-proxy:latest",        "essential": true,        "memoryReservation": <MEMORY_RESV>,        "portMappings": [          {            "hostPort": 0,            "containerPort": 80,            "protocol": "tcp"          }        ],        "links": [          "<APP_NAME>"        ],        "environment": [          {            "name": "LINK_PORT",            "value": "<SERVICE_PORT>"          },          {            "name": "LINK_APP",            "value": "<APP_NAME>"          }        ]      },      {        "name": "<APP_NAME>",        "image": "<IMAGE_NAME>",        "essential": true,        "memoryReservation": <MEMORY_RESV>,        "portMappings": [          {            "protocol": "tcp",            "containerPort": <SERVICE_PORT>          }        ],        "environment": [          {            "name": "PORT",            "value": "<SERVICE_PORT>"          },          {            "name": "APP_NAME",            "value": "<APP_NAME>"          }        ]      }    ],    "requiresCompatibilities": [      "EC2"    ],    "networkMode": "bridge",    "family": "<APP_NAME>"  }

haproxy.cfg:

global    daemon    pidfile /var/run/haproxy.piddefaults    log global    mode http    retries 3    timeout connect 5000    timeout client 50000    timeout server 50000frontend http    bind *:80    http-request set-header X-Forwarded-Host %[req.hdr(Host)]    compression algo gzip    compression type text/css text/javascript text/plain application/json application/xml    default_backend appbackend app    server static "${LINK_APP}":"${LINK_PORT}"

See :

Github : https://github.com/gnokoheat/ecs-reverse-proxy

Docker image : gnokoheat/ecs-reverse-proxy:latest

Here is more detail a solution!


We resolved this issue by swapping to HAProxy.

Another issue was to use the correct format for the Service Dsicovery.

Create a new private namespace with the name _ip.xxxxxxx.ecs and name the service discovery name _prometheus. Both can be achieved when you create a new service in ecs.