# Wrong Content-Type

**URL:** <https://www.ruby-forum.com/t/wrong-content-type/200034>\
**Category:** NGINX\
**Created:** [December 3, 2010, 9:18am UTC](https://www.ruby-forum.com/t/wrong-content-type/200034 "2010-12-03T09:18:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [December 3, 2010, 9:18am UTC](https://www.ruby-forum.com/t/wrong-content-type/200034/1 "2010-12-03T09:18:26Z")

</div>

Hi list,

I’m having a content-type issue with nginx 0.7 on Debian Squeeze.

I have mime.types included in the “http” directive, but when requesting  
CSS or Javascript file, the content type is set to text/html.  
(the application is Roundcube 0.5 beta).

I have found a workaround by adding this in my server declaration:

```
 location ~ \.css {
     add_header Content-Type text/css;
 }

```

But it’s quite ugly. Is there any better way to fix this problem ?

Thanks,  
Julien

---

<div class="post-metadata">

**Author:** ![Julien\_Vehent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@Julien\_Vehent](https://www.ruby-forum.com/u/Julien_Vehent)\
**Post date:** [December 3, 2010, 9:46am UTC](https://www.ruby-forum.com/t/wrong-content-type/200034/2 "2010-12-03T09:46:38Z")

</div>

On Fri, Dec 03, 2010 at 09:17:13AM +0100, Julien Vehent wrote:

> ```
> location ~ \.css {
> add_header Content-Type text/css;
> }
> 
> ```
> 
> But it’s quite ugly. Is there any better way to fix this problem ?

Does nginx proxy these files or handle them as static files ?

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![Julien\_Vehent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@Julien\_Vehent](https://www.ruby-forum.com/u/Julien_Vehent)\
**Post date:** [December 3, 2010, 10:21am UTC](https://www.ruby-forum.com/t/wrong-content-type/200034/3 "2010-12-03T10:21:47Z")

</div>

On Fri, Dec 03, 2010 at 10:16:34AM +0100, Julien Vehent wrote:

> > >
> 
> Static files stored in /var/www and owned by www-data (nginx process  
> owner). It’s the default debian configuration.
> 
> Php5 is fastcgi on a local tcp socket.  
> There is nothing wrong in error.log.

Are these CSS and JS files handled by PHP ?

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![Julien\_Vehent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@Julien\_Vehent](https://www.ruby-forum.com/u/Julien_Vehent)\
**Post date:** [December 3, 2010, 11:18am UTC](https://www.ruby-forum.com/t/wrong-content-type/200034/4 "2010-12-03T11:18:50Z")

</div>

On 12/03/2010 10:20 AM, Igor S. wrote:

> > > > CSS or Javascript file, the content type is set to text/html.  
> > > > Does nginx proxy these files or handle them as static files ?

Good catch ! I don’t know how I missed this, but I was sending ALL of  
the static files to PHP…

My location was set like that:

* * *

## location /roundcube { client\_max\_body\_size 100m; include fastcgi\_params; fastcgi\_index index.php; fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name; fastcgi\_pass 127.0.0.1:9000; }

## I changed it to add the if constraint and it works fine now:

location /roundcube {  
client\_max\_body\_size 100m;  
include fastcgi\_params;  
fastcgi\_index index.php;  
fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;  
if ($uri ~ “.php”){  
fastcgi\_pass 127.0.0.1:9000;  
}  
}

---

<div class="post-metadata">

**Author:** ![Julien\_Vehent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@Julien\_Vehent](https://www.ruby-forum.com/u/Julien_Vehent)\
**Post date:** [December 3, 2010, 10:17am UTC](https://www.ruby-forum.com/t/wrong-content-type/200034/5 "2010-12-03T10:17:22Z")

</div>

On 12/03/2010 09:45 AM, Igor S. wrote:

> > I have found a workaround by adding this in my server declaration:
> > 
> > ```
> > location ~ \.css {
> > add_header Content-Type text/css;
> > }
> > 
> > ```
> > 
> > But it’s quite ugly. Is there any better way to fix this problem ?
> 
> Does nginx proxy these files or handle them as static files ?

Static files stored in /var/www and owned by www-data (nginx process  
owner). It’s the default debian configuration.

Php5 is fastcgi on a local tcp socket.  
There is nothing wrong in error.log.

Julien

---

<div class="post-metadata">

**Author:** ![Julien\_Vehent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@Julien\_Vehent](https://www.ruby-forum.com/u/Julien_Vehent)\
**Post date:** [December 3, 2010, 12:00pm UTC](https://www.ruby-forum.com/t/wrong-content-type/200034/6 "2010-12-03T12:00:53Z")

</div>

On Fri, Dec 03, 2010 at 11:17:57AM +0100, Julien Vehent wrote:

> > > > > I have mime.types included in the “http” directive, but when requesting
> > 
> > Are these CSS and JS files handled by PHP ?  
> > client\_max\_body\_size 100m;  
> > client\_max\_body\_size 100m;  
> > include fastcgi\_params;  
> > fastcgi\_index index.php;  
> > fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;  
> > if ($uri ~ “.php”){  
> > fastcgi\_pass 127.0.0.1:9000;  
> > }  
> > }
> 
> * * *

This is wrong way to it: you should use just locations:

location /roundcube/ {  
location ~ .php {  
client\_max\_body\_size 100m;  
fastcgi\_pass 127.0.0.1:9000;  
include fastcgi\_params;  
fastcgi\_index index.php;  
fastcgi\_param SCRIPT\_FILENAME  
$document\_root$fastcgi\_script\_name;  
}  
}

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**
