nginx重写caching图像的规则

目前我们正在将所有的服务从apache2迁移到nginx,但是目前还停留在特定的重写规则中。 apache中的规则是检查caching的图像/缩略图是否存在,如果存在,则直接发送输出。 否则会将请求重写到image processing器。

# if cached version exists, output directly RewriteCond %{QUERY_STRING} ^(Guest|Member|avatar|tagged|thumb)$ RewriteCond %{DOCUMENT_ROOT}/cache/$1/%{QUERY_STRING}.jpg -f RewriteRule (.*)\.jpg$ /cache/$1/%{QUERY_STRING}.jpg [L] # otherwise redirect all jpg-image-requests to processing # script if they are not in cache dir RewriteCond %{REQUEST_URI} !^/cache RewriteRule \.jpg$ /image_processing.php [QSA,L] 

我们尝试了几个try_files方法,但是到目前为止我们失败了。 有人可以帮助将这个重写规则移植到Nginx吗?

非常感谢你!

如果你向我们展示了你已经尝试过的东西,这将会变得简单多了,但是从我的头顶上来看,这样的事情应该可以做到(假设你有一个虚拟主机的root参数集;如果没有,无论如何,你会想要解决的):

 location ~ ^.*/.*\.jpg$ { try_files $uri @image_processor; } location @image_processor { include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $documentroot/image_processing.php; fastcgi_pass unix:/home/user/something/php.sock; } 

我不知道你在第一个街区想要达到什么目的。 我无法理解为什么你会使用这样的查询string。