Search code examples
phpnginxcharacter-encodingphp-5.3iso-8859-1

Nginx : UTF-8 charset instead of ISO-8859-1


I want my Nginx output ISO-8859-1 and not UTF-8 :

#curl -I www.xyz.com
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 26 Feb 2016 15:36:47 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
X-Powered-By: PHP/5.3.10-1ubuntu3.21
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

I had this in my conf :

server {
  ...
  charset iso-8859-1;
  ...
}

I tried to put it in my etc/nginx/nginx.conf, in my etc/nginx/site-enabled/app.conf, almost in every place I can but no luck...

This is my locale :

#locale
LANG=fr_FR.UTF-8
LANGUAGE=
LC_CTYPE="fr_FR.UTF-8"
LC_NUMERIC="fr_FR.UTF-8"
LC_TIME="fr_FR.UTF-8"
LC_COLLATE="fr_FR.UTF-8"
LC_MONETARY="fr_FR.UTF-8"
LC_MESSAGES="fr_FR.UTF-8"
LC_PAPER="fr_FR.UTF-8"
LC_NAME="fr_FR.UTF-8"
LC_ADDRESS="fr_FR.UTF-8"
LC_TELEPHONE="fr_FR.UTF-8"
LC_MEASUREMENT="fr_FR.UTF-8"
LC_IDENTIFICATION="fr_FR.UTF-8"
LC_ALL=

I have no idea on what to do next...

NB : I work on a docker container to replicate an old server running PHP5.3 because I need REGISTER_GLOBAL..


Solution

  • If the charset is already defined in the Content-Type header by PHP, Nginx default behaviour is to not touch the charset. To change this behaviour you would have to set the override_charset directive to "on".

    I'm assuming you haven't tried this, but you should rather set the default_charset in your php.ini to the charset you want, instead of converting it with Nginx.