# MIME type ('text/html') is not a supported, 404, static files, NGINX, uWSGI, Production

**URL:** <https://forum.djangoproject.com/t/mime-type-text-html-is-not-a-supported-404-static-files-nginx-uwsgi-production/10459>\
**Category:** Deployment\
**Created:** [November 9, 2021, 10:51am UTC](https://forum.djangoproject.com/t/mime-type-text-html-is-not-a-supported-404-static-files-nginx-uwsgi-production/10459 "2021-11-09T10:51:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![blaketig](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/blaketig/32/6323_2.png) [@blaketig](https://forum.djangoproject.com/u/blaketig)\
**Post date:** [November 9, 2021, 10:51am UTC](https://forum.djangoproject.com/t/mime-type-text-html-is-not-a-supported-404-static-files-nginx-uwsgi-production/10459/1 "2021-11-09T10:51:52Z")

</div>

I get the following “MIME type (‘text/html’) is not a supported” error for .css static files, nav\_sidebar.js from the admin site gives:

> ERR\_ABORTED 404 (Not Found)

This is my first time trying to set up a production environment. Below is the setup and file contents:

I split settings files into local.py, pro.py and base.py

In base.py I have:

```auto
BASE_DIR = Path( __file__ ).resolve().parent.parent.parent
STATIC_URL = "/static/"
STATIC_ROOT = str(BASE_DIR / "staticfiles")
STATICFILES_DIRS = [str(BASE_DIR / "static")]

```

The .css loads fine for the development environment when I run:

`python3 manage.py runserver --settings=mysite.settings.local`

For production I run:

`uwsgi --ini config/uwsgi.ini`

My uwsgi.ini file contains:

```auto
[uwsgi]
module = mysite.wsgi:application
env = DJANGO_SETTINGS_MODULE=mysite.settings.pro
master = true
pidfile = /tmp/project-master.pid
http = 127.0.0.1:8000
uid = 1000
virtualenv = /home/pi/.virtualenvs/mysite/
socket = /tmp/mysite.sock
chmod-socket = 666
pythonpath = /home/pi/projects/mysite/mysite
chdir = /home/pi/projects/mysite/mysite

```

When I refresh the browser, the terminal shows:

> [pid: 14751|app: 0|req: 6/6] 127.0.0.1 () {42 vars in 743 bytes} [Tue Nov 9 09:32:40 2021] GET /static/css/base.css =\> generated 179 bytes in 10 msecs (HTTP/1.1 404) 5 headers in 158 bytes (1 switches on core 0)

The admin site shows in terminal with:

> [pid: 15705|app: 0|req: 9/9] 127.0.0.1 () {38 vars in 722 bytes} [Tue Nov 9 09:48:13 2021] GET /static/admin/js/nav\_sidebar.js =\> generated 179 bytes in 10 msecs (HTTP/1.1 404) 5 headers in 158 bytes (1 switches on core 0)

I edited the /etc/hosts file to include the sample domain:

> 127.0.0.1 mysite(dot)com www.mysite(dot)com

The site loads at htt(p)://mysite(dot)com:8000/ but the Chromium console gives an error:

> Refused to apply style from ‘(http)://mysite(dot)com:8000/static/css/base.css’ because its MIME type (‘text/html’) is not a supported stylesheet MIME type, and strict MIME checking is enabled.

I run collectstatic:  
`python3 manage.py collectstatic --settings=mysite.settings.pro`

Then manually move the static files from /staticfiles to /static in the root project folder.

I added this fix from a similar forum post about MIME type, into base.py with no effect:

```auto
import mimetypes
mimetypes.add_type("text/css", ".css", True)

```

The direct path to (http)://mysite(dot)com:8000/static/css/base.css results in:

> Not Found The requested resource was not found on this server.

```auto
In my project folder I have config/nginx.conf which contains:

	location /static/ {
		alias /home/pi/projects/mysite/mysite/static/;
	}

```

My base.html template has:

```auto
{% load static %}
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>{% block title %}Base Template{% endblock title %}</title>
		<link href="{% static 'css/base.css' %}" rel="stylesheet">
	</head>

```

I’m using a Raspberry Pi 3B with standard Raspbian Debian (Buster), Chromium browser, Django 3.2.9, NGINX and uWSGI.

The project is a hello world style app wtih nginx and uwsgi installed via pip:

```auto
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'myapp.apps.MyappConfig',
]

```

Any suggestions to get the static files working? Thanks. The main reason I’m trying to get production working is to continue integrating services which require https which I’m unable to get in the development environment and in the meantime I can’t load static files. I edited the links due to the post link restrictions.

---

<div class="post-metadata">

**Author:** ![CodenameTim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/codenametim/32/31507_2.png) [@CodenameTim](https://forum.djangoproject.com/u/CodenameTim)\
**Post date:** [November 9, 2021, 4:35pm UTC](https://forum.djangoproject.com/t/mime-type-text-html-is-not-a-supported-404-static-files-nginx-uwsgi-production/10459/2 "2021-11-09T16:35:02Z")

</div>

There could be multiple things going on, but let’s focus on getting the static files to be served.

> [@blaketig](#):
>
> I run collectstatic:  
> `python3 manage.py collectstatic --settings=mysite.settings.pro`
> 
> Then manually move the static files from /staticfiles to /static in the root project folder.

I think the problem lies somewhere in this. You shouldn’t have to move files manually, `collectstatic` should be doing that for you. `collectstatic` should be moving the files to `/home/pi/projects/mysite/mysite/static/` when run with `--settings=mysite.settings.pro`.

Try changing `alias /home/pi/projects/mysite/mysite/static/;` to the absolute path of `STATIC_ROOT` when using your `pro` settings.

That should resolve the issue of the http)://mysite(dot)com:8000/static/css/base.css not resolving. Then retry hitting the landing page and see if there’s still a mimetype error.

---

<div class="post-metadata">

**Author:** ![blaketig](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/blaketig/32/6323_2.png) [@blaketig](https://forum.djangoproject.com/u/blaketig)\
**Post date:** [November 10, 2021, 2:30am UTC](https://forum.djangoproject.com/t/mime-type-text-html-is-not-a-supported-404-static-files-nginx-uwsgi-production/10459/3 "2021-11-10T02:30:22Z")

</div>

I changed /home/pi/projects/mysite/mysite/config/nginx.conf however (http)://mysite(dot)com:8000/static/css/base.css is still not resolving.

config/nginx.conf:

```auto
upstream mysite {
	server unix:///tmp/mysite.sock;
}

server {
	listen	80;
	server_name	www.mysite(dot)com mysite(dot)com;
	
	access_log	off;
	error_log	/home/pi/projects/mysite/mysite/logs/nginx_error.log;
	
	location / {
		include	/etc/nginx/uwsgi_params;
		uwsgi_pass	mysite;
	}

	location /static/ {
		alias /home/pi/projects/mysite/mysite/staticfiles/;
	}

	location /media/ {
		alias /home/pi/projects/mysite/mysite/media/;
	}

}

```

When I run `python3 manage.py collectstatic --settings=mysite.settings.pro`, the /staticfiles folder is created with the static files inside. The /static folder in the same project root remains empty if I don’t do any copying over manually.

If I don’t have a /static folder in the project root, django will complain:

> FileNotFoundError: [Errno 2] No such file or directory: ‘/home/pi/projects/mysite/mysite/static’

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [November 10, 2021, 3:06am UTC](https://forum.djangoproject.com/t/mime-type-text-html-is-not-a-supported-404-static-files-nginx-uwsgi-production/10459/4 "2021-11-10T03:06:32Z")

</div>

Couple different odds & ends…

- How are you running nginx such that you have your nginx.conf file inside your project?

- Your STATIC\_ROOT should be completely outside your project. (e.g. `/home/pi/static/`)

- Your nginx configuration should point to that target directory for static.

- That directory (and all files and subdirectories inside it) should be readable by the UID being used to run nginx, but must be writable by the UID being used to run `collectstatic`.

- nginx should have _no_ access to anything in your project directory.

---

<div class="post-metadata">

**Author:** ![blaketig](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/blaketig/32/6323_2.png) [@blaketig](https://forum.djangoproject.com/u/blaketig)\
**Post date:** [November 10, 2021, 5:51am UTC](https://forum.djangoproject.com/t/mime-type-text-html-is-not-a-supported-404-static-files-nginx-uwsgi-production/10459/5 "2021-11-10T05:51:16Z")

</div>

> - How are you running nginx such that you have your nginx.conf file inside your project?

I added include /home/pi/projects/mysite/mysite/config/nginx.conf; to the top of my /etc/nginx/nginx.conf file.

so /etc/nginx/nginx.conf is:

```auto
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
	worker_connections 768;
	# multi_accept on;
}

http {
	##
	# Basic Settings
	##
	include /home/pi/projects/mysite/mysite/config/nginx.conf;
...

```

> - Your STATIC\_ROOT should be completely outside your project. (e.g. `/home/pi/static/` )

I’ve moved it to `/home/pi/static/` and updated base.py settings to `STATIC_ROOT = "/home/pi/static"`

> - Your nginx configuration should point to that target directory for static.

I’ve updated /home/pi/projects/mysite/mysite/config/nginx.conf to point to /home/pi/static;

```
location /static/ {
	alias /home/pi/static;
}

```

> - That directory (and all files and subdirectories inside it) should be readable by the UID being used to run nginx, but must be writable by the UID being used to run collectstatic.

I’m currently running nginx from one virtual environment terminal with:

`(mysite) pi@raspberrypi:~ $ sudo nginx`

I’m running collectstatic from another virtual environment terminal with:

`(mysite) pi@raspberrypi:~/projects/mysite/mysite $ python3 manage.py collectstatic --settings=mysite.settings.pro`

When running collectstatic, the static files now get put into new /home/pi/static folder.

When I go to (http)://127.0.0.1/ I get the Welcome to nginx! page and when I go to (http)://mysite(.)com/ I get my hello world page but still with the Chromium console error:

`Refused to apply style from 'http://mysite.com/staticfiles/css/base.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled`

The Network tab in Chromium shows the base.css file Status as `(canceled)` and Type as `stylesheet`.

---

<div class="post-metadata">

**Author:** ![blaketig](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/blaketig/32/6323_2.png) [@blaketig](https://forum.djangoproject.com/u/blaketig)\
**Post date:** [November 10, 2021, 6:09am UTC](https://forum.djangoproject.com/t/mime-type-text-html-is-not-a-supported-404-static-files-nginx-uwsgi-production/10459/6 "2021-11-10T06:09:05Z")

</div>

In my above post I noticed the MIME type error is referring to staticfiles. So I’ve updated the base.py from `STATIC_URL = '/staticfiles/'` to `STATIC_URL = '/static/'`

So all static files settings in base.py are:

```auto
STATIC_URL = '/static/'
STATIC_ROOT = '/home/pi/static'
STATICFILES_DIRS = [str(BASE_DIR / "static")]

```

When I go to (http)://mysite.com, the Chromium error is:  
`mysite.com/:7 GET http://mysite.com/static/css/base.css net::ERR_ABORTED 404 (Not Found)`

When I go to (http)://mysite.com:8000, the Chromium error is:  
`mysite.com/:1 Refused to apply style from 'http://mysite.com:8000/static/css/base.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.`

---

<div class="post-metadata">

**Author:** ![CodenameTim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/codenametim/32/31507_2.png) [@CodenameTim](https://forum.djangoproject.com/u/CodenameTim)\
**Post date:** [November 10, 2021, 1:41pm UTC](https://forum.djangoproject.com/t/mime-type-text-html-is-not-a-supported-404-static-files-nginx-uwsgi-production/10459/7 "2021-11-10T13:41:28Z")

</div>

Hi blaketig, please confirm the first half of this statement from @KenWhitesell:

> [@KenWhitesell](#):
>
> That directory (and all files and subdirectories inside it) should be readable by the UID being used to run nginx, but must be writable by the UID being used to run `collectstatic` .

You’ve already confirmed that `collectstatic` can write to that directory, but you haven’t confirmed that the files can be read from that directory which might explain why nginx isn’t serving them.

---

<div class="post-metadata">

**Author:** ![blaketig](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/blaketig/32/6323_2.png) [@blaketig](https://forum.djangoproject.com/u/blaketig)\
**Post date:** [November 12, 2021, 2:14am UTC](https://forum.djangoproject.com/t/mime-type-text-html-is-not-a-supported-404-static-files-nginx-uwsgi-production/10459/8 "2021-11-12T02:14:11Z")

</div>

I did:  
`sudo chown pi:pi .`  
In folder:  
`/var/www/html`

Then updated STATIC\_ROOT = ‘/var/www/html/static’  
Now it’s working. Thanks

---

<div class="post-metadata">

**Author:** ![BrianZhang1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/brianzhang1/32/17843_2.png) [@BrianZhang1](https://forum.djangoproject.com/u/BrianZhang1)\
**Post date:** [December 17, 2023, 10:07pm UTC](https://forum.djangoproject.com/t/mime-type-text-html-is-not-a-supported-404-static-files-nginx-uwsgi-production/10459/9 "2023-12-17T22:07:53Z")

</div>

THANK YOU! I’ve been struggling with this for so long, my page was loading, the css file loaded, there were no errors, but the stylesheet didn’t actually apply. Just silently failed and I was ripping my hair out. Such a small oversight. Thanks again for the solution!
