atom feed2 messages in ru.sysoev.nginxX-Accel-Redirect can't deal with un-a...
FromSent OnAttachments
wang...@routon.comApr 7, 2011 3:28 am 
wang...@routon.comApr 7, 2011 3:29 am 
Subject:X-Accel-Redirect can't deal with un-ascii file name
From:wang...@routon.com (wang@routon.com)
Date:Apr 7, 2011 3:29:53 am
List:ru.sysoev.nginx

Hi, all! I have some files with un-ascii name, and I want to use X-Accel-Redirect to control the download access. This is my nginx-conf:

server { listen 80; server_name update.grandes.com.cn; access_log logs/grandes_access.log main; location /update/download { rewrite ^/update/download/(.+)$ /update/download.action?path=$1 last; proxy_pass http://localhost:8080; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; client_max_body_size 10240m; client_body_buffer_size 128k;

proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90;

proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } location /data/ { root /usr/local; internal; proxy_hide_header X-Accel-Redirect; add_header ETag $upstream_http_etag; } }

And this's the code of '/update/download.action' running in tomcat server,

public String file() { response.setHeader("X-Accel-Charset", "utf-8"); response.setHeader("X-Accel-Redirect", path);

return NONE; }

When access the path 'http://update.grandes.com.cn/update/download/WH2HOSIPTV/%E6%97%A5%E5%BF%97.txt', nginx server report 500 Internal Server Error. Then I see the log, the tomcat server print the path parameter like this 'WH2HOSIPTV/日志.txt' which is right, but the nginx log track like this; 2011/04/07 18:12:56 [crit] 2056#5500: *1 CreateFile() "/usr/local/data/WH2HOSIPTV/遄.txt" failed (1113: No mapping for the Unicode character exists in the target multi-byte code page), client: 127.0.0.1, server: update.grandes.com.cn, request: "GET /update/download/WH2HOSIPTV/%E6%97%A5%E5%BF%97.txt HTTP/1.1", upstream: " http://127.0.0.1:8080/update/download.action?path=WH2HOSIPTV/%e6%97%a5%e5%bf%97.txt ", host: "update.grandes.com.cn".

I try to run nginx and tomcat server both in Red Hat Enterprise Linux AS release 4 with environment variables LANG=zh_CN.UTF-8 and windows xp which charset is GBK, and try to change X-Accel-Charset to 'GBK', the nginx always report 500 error. The problem existes both in nginx-0.8.54 and nginx-0.9.6. But when I change the code in '/update/download.action' like this, it works fine! Is this a bug of nginx?

public String file() { response.setHeader("X-Accel-Charset", "utf-8"); response.setHeader("X-Accel-Redirect", new String(path.getBytes("utf-8"), "iso-8859-1"));

return NONE; }

Best regards