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

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


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.


Check if your PHP script is not explicitly outputting a charset attribute. If not, then I guess that the default PHP configuration in Ubuntu (it is the default in Debian) is to add the UTF-8 charset, and from now on you can only change it in nginx by setting up a conversion table to go back from UTF-8 to ISO-8859-1 again, which is a waste (and takes time to setup).

So basically, you have three two options:

  1. Change your script to add a charset=iso-8859-1 attribute explicitly in the Content-type header.

  2. Change your default_charset option in php.ini. This, however, will change the default character in all PHP scripts run by your nginx servers (i.e. you'd better know what are you doing).

  3. Change the default charset only in the FPM block used by your ISO-8859-1 server. This can be accomplished by adding the following line to your FPM configuration block: fastcgi_param PHP_ADMIN_VALUE "default_charset=iso-8859-1";

EDIT: In the end, option 3 actually will set default_charset on PHP-FPM as they're scheduled for your server, and the option will stick, so it's pretty much the same as 2, only more unpredictable.