NGINX – How to Enable Correct Charset HTTP Header

charsethttpnginx

What is the right way to enable correct charset headers in NGINX?

I'm analyzing my website with Google Page Speed. It says that I should specify the charset of HTML files in HTTP-headers. What is the right way to do this?

I already tried to set charset utf-8; in the server {} declaration of my NGINX configuration file, but it hasn't got any effect.

My server responds with the following header:

Connection: keep-alive
Date: Fri, 16 Sep 2011 12:43:24 GMT
Last-Modified: Fri, 02 Sep 2011 15:13:17 GMT
Server: nginx/0.7.67

Thank you.

Best Answer

Adding charset utf-8; is pretty much everything you need to do. Are sure that you didn't forget to reload nginx after you changed the configuration file?

Besides at the moment of writing, curl -I http://vorb.de/ returns the following result:

HTTP/1.1 200 OK
Server: nginx/0.7.67
Date: Fri, 16 Sep 2011 13:20:03 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 1705
Last-Modified: Fri, 02 Sep 2011 15:13:17 GMT
Connection: keep-alive
Vary: Accept-Encoding
Accept-Ranges: bytes

So everything looks ok now.