T
T
tmitry2015-12-02 15:15:42
Nginx
tmitry, 2015-12-02 15:15:42

Why is nginx giving wrong charset response header?

In the settings of the nginx virtual server, the encoding is set:

server {
    listen       80;
    server_name  example.dev;
    root         /Users/macbook/sites/example.dev/www;

    charset	 windows-1251;
    
    location / {
    ....
    }
}

But the server returns the wrong response header - utf-8

user:~ macbook$ curl -I example.dev
HTTP/1.1 200 OK
Server: nginx/1.8.0
Date: Wed, 02 Dec 2015 12:13:51 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.16
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache

Maybe someone faced a similar situation?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Belyaev, 2015-12-02
@tmitry

X-Powered-By: PHP/5.6.16
php rewrites the Content-type header
accordingly win-1251 will be only for statics You
look in the php code
if there is still a back server between php and ngnix (for example apache) you also need to check its config

S
simonnik, 2015-12-24
@simonnik

default_charset string
In PHP 5.6 and later, "UTF-8" is the default value and is used as the default encoding for the htmlentities(), html_entity_decode(), and htmlspecialchars() functions if the encoding parameter is not specified. The default_charset value is also used to specify the default encoding for iconv functions if the iconv.input_encoding, iconv.output_encoding, and iconv.internal_encoding configuration options are not set, and for mbstring functions if mbstring.http_input mbstring.http_output mbstring.internal_encoding is not set.
All versions of PHP use this value as the encoding for the standard Content-Type header sent by PHP, unless that header is overridden by a call to the header() function.
It is not recommended to set default_charset to an empty value

And since it is not recommended, it means that in the scripts themselves, through the header, change charset
header('Content-Type: text/html; charset=windows-1251');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question