# Nginx, MIME types and Firefox



## MannDude (Mar 31, 2014)

Yesterday and the day before pushed out some updates on the forum (server side for the WWW and Ad server), to speed things up a tad. This included updating Nginx  and some SSL and Gzip related tweaks.

However it's come to my attention today that the ads now display strangely in FireFox, and FireFox only. I normally use Chromium myself, but can confirm the error exists in Iceweasel/Firefox. Load the site in each browser and you'll see what I am referring to.

Someone mentioned to me the following:



> This error message seems to be specific to Firebug, but is not a bug in Firefox (no other browser / plugin seems to point this out, or even recognise this as an error). I inspected a single request to vpsboard.com, and right at the end of the page load there was this invalid request:


The stylesheet https://u628b3.vpsboard.com/static/css/main.css was not loaded because its MIME type, "application/octet-stream", is not "text/css"

But I'm not quite sure how to correct this so that Firefox recognizes the file as text/css properly. It seems that the solution is server side. Nginx needs to send the correct MIME type for files with a .css extension. I am not entirely sure how to do this though. Any thoughts?


----------



## Shados (Mar 31, 2014)

`/etc/nginx/mime.types` should have a line like "text/css css;"


----------



## MannDude (Mar 31, 2014)

Shados said:


> `/etc/nginx/mime.types` should have a line like "text/css css;"


It does already, but this as if it's probably due to gzip altering the MIME type and Firefox is treating it differently than Chrome. Only in Firefox does it not detect it as 'text/css'.


----------



## Nett (Mar 31, 2014)

Gzip is probably the issue . Have you tried to minimise the CSS file and disable Gzip for .css?


----------



## MannDude (Mar 31, 2014)

Hmm, I removed  _text/css_ from _"gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;"_ in nginx.conf... restarted nginx. Didn't fix the issue. Then just disabled gzip entirely on the server and the issue persists.

Any ideas?


----------



## Nett (Mar 31, 2014)

What's the HTTP response header?


----------



## manacit (Mar 31, 2014)

I don't think it's a gzip issue - requesting the page without an Accept: Gzip header with curl gives me the following HTTP response:


```
$ curl -I https://u628b3.vpsboard.com/static/css/main.css
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 31 Mar 2014 20:02:12 GMT
Content-Type: application/octet-stream
Content-Length: 426
Last-Modified: Sun, 19 Jan 2014 05:36:27 GMT
Connection: keep-alive
ETag: "52db645b-1aa"
Accept-Ranges: bytes
```
The application/octet-stream header tells me that nginx isn't reading your mime type file correctly. Inside nginx.conf, make sure you have a line that resembles the following:


```
include       mime.types;
```
If you don't, it will send files as the default mime type, which is application/octet-stream. For the record, this is what mine looks like: https://gist.github.com/nickvanw/9901057


----------



## MannDude (Mar 31, 2014)

manacit said:


> I don't think it's a gzip issue - requesting the page without an Accept: Gzip header with curl gives me the following HTTP response:
> 
> 
> $ curl -I https://u628b3.vpsboard.com/static/css/main.css
> ...


Man oh man. It's alway something simple, isn't it!

nginx.conf was indeed missing 'include mime.types;'

Re-enabled gzip as well. Everything is working fine. May need to hard refresh or clear cache if using FF, but afterwards everything displays normally!


----------



## manacit (Mar 31, 2014)

Woohoo!


----------

