I'm building a django web application on an ec2 instance that's in an autoscaling group and fronted with an Application Load Balancer.
I've configured uwsgi and nginx and when I run the command
uwsgi --socket /tmp/uwsgi.sock --module MyProject.wsgi --chmod-socket=666 --virtualenv /path/to/my/virtual/env/
Everything works great when I access the application through the IP adress. I can navigate to the site and everything works well.
However, when I try and access the website through the URL using the domain name that I own and registered though Route 53, the website's functionality works and is being served, but the static content (css files, etc) aren't rendering.
My Auto-Scaling Group says the instance is healthy. The target group says the targets are healthy. The ALB is listening on ports 80 and 443 and forwarding the traffic to the Target Group.
Does anyone know why the static content isn't rendering when going through the registered domain name even though it works when accessing it directly through the Public IP Address?
It sounds like your static content urls are not resolving to your domain. You should check the url being given on your templates is what is expected and then ensure that nginx is properly set up to serve content from that location.
server {
root /www/data;
location /static/ { # serve files from /www/data/static/ to /static/
}
}
https://docs.nginx.com/nginx/admin-guide/web-server/serving-static-content/
you may also wish to refer to the django static files doc, perhaps you need to make sure your settings are correct to map to the correct url.
https://docs.djangoproject.com/en/2.1/howto/static-files/deployment/
I would recommend configuring your instances to serve static content from s3 instead as this will make more sense if you have multiple server instances whose static/media files will need to be synced.