Can nginx override encoding of Tomcat back end?

I have been trying for some time now to get Tomcat to serve everything
with UTF-8 encoding, but some pages keep coming back with ISO-8859-1
encoding. As Tomcat is sitting behind an nginx remote proxy server, I
was wondering whether I could configure nginx to override the encoding
automatically? I have added ‘charset utf-8’ in the server block but this
by itself obviously doesn’t do the trick. Can I set some response
headers, perhaps?

On Fri, Nov 25, 2011 at 02:51:24PM +0000, John M. wrote:

I have been trying for some time now to get Tomcat to serve everything
with UTF-8 encoding, but some pages keep coming back with ISO-8859-1
encoding. As Tomcat is sitting behind an nginx remote proxy server, I
was wondering whether I could configure nginx to override the encoding
automatically? I have added ‘charset utf-8’ in the server block but this
by itself obviously doesn’t do the trick. Can I set some response
headers, perhaps?

You can try this, but nginx will scan response body with ISO-8859-1
trying to convert it to utf-8:

http {
charset_map iso-8859-1 utf-8 {}

server {
    charset           utf-8;
    override_charset  on;


Igor S.

On 25/11/11 15:16, Igor S. wrote:

Thanks Igor. I tried this, but it’s still leaving the encoding as
ISO-8859-1 (as reported under Page Info in Firefox). This is 0.6.32 on
Windows - I don’t know whether a more recent version would help?

JM

On Fri, Nov 25, 2011 at 03:24:18PM +0000, John M. wrote:

     override_charset  on;

Thanks Igor. I tried this, but it’s still leaving the encoding as
ISO-8859-1 (as reported under Page Info in Firefox).

Are you sure that Firefox did not get it from cache ?

This is 0.6.32 on
Windows - I don’t know whether a more recent version would help?

Where have you found such version ?
The first nginx/Windows version was 0.7.52.
There were some change in charset module in 0.8.0, so you can try
more modern version.


Igor S.

Igor, thanks for the suggestion. This is now working as it should!

On 25/11/11 15:34, Igor S. wrote:

Are you sure that Firefox did not get it from cache ?

Pretty sure. Just doing some checking as there are some strange things
going on…

This is 0.6.32 on
Windows - I don’t know whether a more recent version would help?

Where have you found such version ?
The first nginx/Windows version was 0.7.52.
There were some change in charset module in 0.8.0, so you can try
more modern version.

It was one of the Kevin W. versions. To be honest I’ve not
really looked at it in a long while. I’ll install a newer version and
report back.

JM