Forum: NGINX Migrate from apache mod_rewrite

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Andreas Lehr (Guest)
on 2009-02-09 17:01
(Received via mailing list)
Hi guys,

I`m trying to migrate one of our external programmed tools to nginx from
  traditional apache.

But unfortunately I screw things up on migrating apache mod_rewrite to
nginx mod_rewrite!

Would be great, if one of you could help me on this.
The mod_rewrite sections in apache looks like this:

     RewriteEngine On

     # if thumb exists, output directly
     RewriteCond %{QUERY_STRING} ^(thumb|normal)$
     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]

How to do this with nginx?

Thank you very very much!
Igor S. (Guest)
on 2009-02-09 17:27
(Received via mailing list)
On Mon, Feb 09, 2009 at 03:52:21PM +0100, Andreas Lehr wrote:

> How to do this with nginx?

If you use 0.6.35, then get
and try the following:

server {


     set $image "";

     if ($uri ~ (.*)\.jpg$) {
         set  $image  $1;

     location ~ (.+)\.jpg$ {
         try_files  /cache/$image/$args.jpg  @image;

     location @images {
         proxy_pass  http://backend/image_processing.php;


I do want to add captures in regex location's:

     location ~ (.+)\.jpg$ {
         try_files  /cache/$1/$args.jpg  @image;
This topic is locked and can not be replied to.