0

I have Django rest API application and swagger for that is working fine locally. I am trying to configure it using containers and deploy it on ECS.

Now when I build and run the container the application works fine (I mean the swagger UI is appearing). When I attach the application load balancer to it, on the browser it is giving me 404 files not found for js and CSS files.

Here is the console output from the web browser.

Web Broswer Console Error

Here is my Nginx config file

# nginx.default
add_header X-Content-Type-Options nosniff;
include /etc/nginx/mime.types;
add_header X-XSS-Protection "1; mode=block";

server {
    listen 8020;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    
    location / {
        proxy_pass http://127.0.0.1:8010;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    location /static {
        root /home/app/codebase;
    }
}

THe path of static folder inside docker container is /home/app/codebase/static/

Also added the following lines in the Django Settings.py file.

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

Not sure what am I missing. Any leads will be appreciated. I have looked into these questions. The problem is something similar but not sure what I'm missing.

Ali Hassan
  • 321
  • 2
  • 17

1 Answers1

1

Posting the solution in case anyone still facing the same kind of issue. I provisioned all the resources using IaC (Cloud Formation) so while provisioning Load Balancer I created the one target group but at that time the ECS services were not created, so I created a dummy target group that drops the traffic and was not routing the traffic to any service. Incorrect Dummy Target Group And in ALB's path-based routing, the last route (which the traffic uses when the request does not find any route) was directing traffic to a dummy target group. As soon as I changed the target group everything works like a charm.

Working Fine Correct Target Group

Pro Tip: Always use any of the target groups from your application in the last ALB rule.

Ali Hassan
  • 321
  • 2
  • 17