Mime Type error from AWS Elastic Beanstalk

Viewed 332

I deployed my django project to aws elastic branstalk. I followed all the steps. In EBS console, project health seems Ok. When I try to run the project, I get the following error. `Refused to apply style from '' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Here is my css and js addresses:

<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}" />

<script src="{%static 'js/jquery.min.js'%}"></script>

How can I fix this issue?

1 Answers

First you have to go to your settings.py and do the following:

  • Set DEBUG = False (the default installation comes with DEBUG = True)
  • Add STATIC_ROOT = 'static'

Then you have to tell EB where your static files are gonna be. For that, create a file inside .ebextensions folder, at the root, named staticfiles.config (can be any name with .config extension). Write this inside:

container_commands:
  collectstatic:
    command: "source /var/app/venv/*/bin/activate && python3 manage.py collectstatic --noinput"
option_settings:
  aws:elasticbeanstalk:environment:proxy:staticfiles:
    /static: static

And that's it. I was very confused by the documentation, even the official tutorials are wrong. After a lot of research and tries, that's the solution that I came up to use.

Related