Setting Charset on Nginx PHP virtual host

Vincent M. mouseless at free.fr
Wed Jul 31 15:29:37 UTC 2019


Hello,

I tried to set the Charset of a virtual host like this:

server {
         root /var/www/mywebsite.com;

...

         charset iso-8859-1;
         override_charset on;

...

         location ~ \.php$ {
                 include snippets/fastcgi-php.conf;
                 fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
                 charset iso-8859-1;
                 override_charset on;

         }
}

I have specified charset and overried_charset on both server and 
location and yet, it was still sending headers in UTF-8.

I had to modify the php.ini file from /etc/php/7.2/fpm/php.ini to 
specify in it default_charset = "iso-8859-1".

But I would like to let my php set to UTF-8 and specify on Nginx only 
for only one virtual host iso-8859-1.

On Apache we can do:

<VirtualHost mywebsite.com:80>
...
     Header set Content-Type "text/html; charset=iso-8859-1"
</VirtualHost>

How to do the same on Nginx?

Thanks,

Vincent.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20190731/35e2a2b0/attachment.html>


More information about the nginx mailing list