Forum: NGINX Migrate from apache mod_rewrite

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B2bbd32968d60d85b65ad2f0bd08adb3?d=identicon&s=25 Andreas Lehr (Guest)
on 2009-02-09 16: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!
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-02-09 16: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
http://sysoev.ru/nginx/patch.try_files.0.6.35
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.