Good day to all. I had a little problem with the site. The sysadmin went on vacation and you have to pick the problems on the server yourself. The problem is this: Previously, the site was running Apache2 . Recently, in view of the need, it was transferred under the control of nginx + php-fastcgi . The site is working fine. But there was a problem with the display of preview images. They are processed by a special controller. For this in the file. htaccess was spelled as follows:

 SetEnv APPLICATION_ENV production RewriteEngine On #RewriteRule ^.*(files/.*[\.JPG|\.jpg|\.JPEG|\.jpeg|\.GIF|\.gif|\.PNG|\.png])/(w=.*)$ /tools/imagepreview/?$2&f=/$1 [L,QSA] RewriteRule ^(.*[\.JPG|\.jpg|\.JPEG|\.jpeg|\.GIF|\.gif|\.PNG|\.png])/(w=.*)$ /tools/imagepreview/?$2&f=/$1 [L,QSA] RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L] <IfModule mod_filter.c> <IfModule mod_deflate.c> 

My problem is to correctly override the location for images in nginx . Help who than can. Thank you in advance!

  • Does it even work? [\ .Jpg | \
  • Everything works under Apache2. Under Nginx no. This is actually the problem. It is necessary not to simplify, but correctly determine the location for nginx. - sshchetkin
  • Thank you and answer. I rummaged a bit and solved the problem. It was necessary to register everything just before the very first section of the location: rewrite ^ / (. * [. JPG | .jpg | .JPEG | .jpeg | .GIF | .gif | .PNG | .png]) / (w =. * ) $ /tools/imagepreview/index.php?$2&f=/$1 last; - sshchetkin pm
  • I gave you the right expression :) The person who wrote the original expression did not quite understand how to write them, so I asked about performance. - ReinRaus

1 answer 1

Not strong in nginx, but if I'm not mistaken, then the line with rewrite should be placed either in the server or in the location /

 server { ... rewrite ^(.*\.(?:jpg|JPG|jpeg|JPEG|bmp|BMP|gif|GIF|png|PNG))(w=.*)$ /tools/imagepreview/?$2&f=$1 last; ... } 

Also, regular expressions are most likely not case sensitive, so caps file extensions can be removed.

  • Made the answer, once helped. - ReinRaus