我遇到了与 the one described on this question 类似的问题.然而,我设法用最新的 PCRE(8.30)编译了 nginx(1.0.14),将重写规则更改为使用 UTF8,但仍然失败。
我的重写规则是
location / {
try_files $uri $uri/ /index.php;
rewrite "(*UTF8)^/imgthumb/(.*)$" /timthumb.php?$1 last;
}
这适用于没有 unicode 的图像,但当文件名包含 unicode 字符时失败。
所以 /imgthumb/src=/wp-content/uploads/8姐姐の古いマテリョーシカ.jpg&h=121&w=137&zc=1
失败
但是/imgthumb/src=/wp-content/uploads/MOD0005.jpg&h=121&w=137&zc=1
工作很好。
在使用 .htaccess 重写规则的 Apache 上,它适用于两者
RewriteRule ^/imgthumb/(.*)$/timthumb.php?$1 [L]
我的nginx重写规则错了吗?有什么办法可以做到这一点吗?
更新:
我注意到问题似乎源于这样一个事实,即 PHP 脚本使用 nginx 仅将一个参数 (src) 获取到 $_GET
数组中,但是使用 apache 重写它被分解为不同的参数......
最佳答案
最终的解决方案是 provided by Valentin V. Bartenev on the nginx forum在我在那里发布了同样的问题之后。
用这段代码替换重写规则使这项工作成功!!
location ~ (*UTF8)^/imgthumb/(.*)$ {
fastcgi_pass unix:/var/spool/phpfpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/timthumb.php;
fastcgi_param SCRIPT_NAME /timthumb.php;
fastcgi_param QUERY_STRING $1;
}
关于utf-8 - 使用 pcre 8.3 在 nginx 上使用 unicode url 重写规则失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9757103/