0

I understand that the “charset utf-8” directive in an http or server block of a configuration file should make nginx include “Content-Type: text/html; charset=utf-8” in the headers of a response, instead of only “Content-Type: text/html”.

However, I have added that directive to both the http block and the applicable server block, and the “Content-Type” directive has remained unchanged.

Precautions taken include: 1. Reloading or restarting nginx after each config change. 2. Including a “charset_types text/html text/plain;” directive before. 3. Making an unrelated config change and verifying that it DOES have its expected effect.

I have looked at the related discussions here and at the nginx documentation and not found any explanation.

  • What nginx version? What files are you serving? What is the nginx configuration? – Michael Hampton Feb 24 '18 at 0:10
0

charset utf-8;

in your server{} block should be all you need to do. Based on the nginx documentation here

http://nginx.org/en/docs/http/ngx_http_charset_module.html#source_charset

you can place this in http, server, or location contexts.

0

Thank you for the replies. I finally realized that I was looking at the headers of a 301 response. URLs without a trailing slash are redirected to the same URLs with a trailing slash. The 301 response has “text/html” as its content type. But the following response after the redirect has “text/html; charset=utf-8” as its content type. I don’t know how useful it is for the 301 response to have the charset parameter declared, but, since it does declare text/html as the content type, if the nginx config sets charset in the http block, should we not expect charset in the 301 response, too? The nginx version is 1.10.3 (Ubuntu).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.