stdex
stdex

Reputation: 359

Make nginx return a JSON header

PHP/5.4.45, nginx/1.2.1

My PHP script set correct content/type for json:

header('Content-Type: application/json; charset=UTF-8');

But in server response header:

Content-Type:text/html

How I should change header?

Upvotes: 1

Views: 5227

Answers (2)

chicocvenancio
chicocvenancio

Reputation: 665

Add application/json to the charset_types directive. Be careful to not forget one from the default one. Mine reads like this (default plus application/json)

charset_types text/xml text/plain text/vnd.wap.wml application/javascript application/rss+xml application/json;

Upvotes: 3

Alexandr T
Alexandr T

Reputation: 1501

Add in /etc/nginx/mime.types:

`application/json      json;`

And reload nginx.

Upvotes: 1

Related Questions