Software⏱️ 3 min read📅 2026-06-11

How to Fix: Nginx cannot serve css files because of MIME type error

Nginx MIME type error for CSS files in Django webapp.

Quick Answer: Ensure the MIME type for CSS files is set correctly in the Nginx configuration, specifically in the 'location /static' block.

Nginx is unable to serve CSS files due to a MIME type error, which affects all users of this setup. This issue can be frustrating for developers and end-users alike, as it prevents them from viewing static assets on the website.

The lack of proper MIME type configuration in Nginx's configuration file leads to this problem. The solution involves correcting the MIME types for CSS files.

🛑 Root Causes of the Error

  • The primary reason for this issue is that Nginx does not recognize CSS files by default, resulting in a MIME type error when trying to serve them.
  • An alternative reason could be if there are any typos or incorrect file paths in the configuration file that prevents Nginx from finding and serving the CSS files.

✅ Best Solutions to Fix It

Configuring MIME types for CSS files

  1. Step 1: Open the nginx configuration file and add the following lines under the http section: `add_type application/css .css`.
  2. Step 2: Restart Nginx to apply the changes. This can be done by running the command `/service nginx restart` in the terminal.
  3. Step 3: Verify that CSS files are being served correctly by checking the website's static assets.

Verifying MIME types using the `file` command

  1. Step 1: Open a new terminal and run the command `file /home/ubuntu/mira_website/manageDb/static/css/style.css`.
  2. Step 2: Check if the output includes the string 'application/css', indicating that Nginx has correctly recognized the MIME type for CSS files.

🎯 Final Words

By configuring the correct MIME types for CSS files and verifying their recognition, users can resolve the issue and serve static assets on their website.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions