Im trying to figure out why nginx is trying load some static images with the wrong encoding. E.g.:
From the error.log:
2012/08/08 21:14:46 [error] 17968#0: *71 open()
“/home/www/mydomain.com/WEB-INF/images/productimage/image-ø.png”
failed (2: No such file or directory), client: x.x.x.x, server:
http://www.mydomain.com, request: “GET /images/productimage/image-%C3%B8.png
HTTP/1.1”, host: “www.mydomain.com”, referrer:
“http://www.mydomain.com/”
In my nginx.conf file i added the following;
source_charset utf-8;
charset utf-8;
But unfortunately, that didnt solve it.
My vhost config file uses the following to serve the image files;
location /images/
{
alias /home/www/mydomain.com/WEB-INF/images/;
expires 15d;
}
I’m using ubuntu, with the LANG environment variables set as such;
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
Any clue ? Thanks !
Percent-encoding in URIs is really two steps of encoding, not one. Ideally, first text is encoded as UTF-8, and the UTF-8 text is “percent-encoded” to be used in a URI, producing a result like this:
Can you confirm that this URI has been encoded properly? If you start with the character you want, and then encode it as UTF-8 and then percent-encode it, is the result %C3%B8? You can manually generate a percent-encoded script like this:
Another way to put it: Are your sure the problem is in the decoding by Nginx, and not the encoding? Check the encoding of the HTML page that contains the image reference. Review both the HTTP headers and the meta tags. Make sure it explicitly declares itself as UTF-8. Otherwise, that could be cause for the browser to mis-interpret the reference.
You can likewise manually test the decoding process, like this:
I’ve written a detailed post about percent-encoding with Perl, if that’s of interest as a reference.