How to Set Default Charset to UTF8 in NGINX

set default charset to utf8 in nginx

If your website’s character encoding is broken then it will not render all characters properly and it will lead to poor user experience. By default, NGINX uses windows-1251 charset, which may be limiting for unicode characters. Here’s how to set default charset to UTF8 in NGINX.


How to Set Default Charset to UTF8 in NGINX

Here are the steps to set default charset to UTF8 in NGINX.


1. Open NGINX config file

Open NGINX config file in a text editor. It is generally found in /etc/nginx/nginx.conf.

$ sudo vim /etc/nginx/nginx.conf


2. Set Default Charset to UTF8

Simply add the following line in server, http, or location context

charset UTF-8;



3. Reload NGINX web server

Reload NGINX server to apply changes.

$ sudo service nginx reload


4. Test default character encoding

Type the following command

$ wget --server-response -O /dev/null http://your_domain_or_server_ip


$ curl -I http://your_domain_or_server_ip

Sample output:

HTTP/1.1 200 OK
Server: nginx
Date: Mon, 05 Nov 2018 16:42:51 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Whom: l2-com-cyber
Vary: Cookie
Last-Modified: Mon, 05 Nov 2018 16:38:02 GMT
Cache-Control: max-age=311, must-revalidate
X-Galaxy: Andromeda-1
X-Origin-Type: DynamicViaDAL

That’s it! Now NGINX will automatically set default character encoding to UTF8

About Sreeram Sreenivasan

Sreeram Sreenivasan is the Founder of Ubiq, a business dashboard & reporting platform for small & medium businesses. Ubiq makes it easy to build business dashboards & reports for your business. Try it for free today!