On Wed, Mar 18, 2015 at 3:46 AM, Karl Johnson <karljohnson...@gmail.com> wrote:
> Thanks for the reply Nurahmadie. > > I changed the location to ~ ^/static/ and the rewrite works again. I've > added a "expires 1w;" in this location to add an expire on all images in > /static but it doesn't seem to apply, images give 200 OK and never cache. > Is it the right way to do it? > > location ~ ^/static/ { > rewrite ^/static/images/([0-9])\-([0-9]+)x([0-9]+)/(.*)$ > /image-fa013d.php?zc=$1&w=$2&h=$3&src=../uploads/images/$4; > expires 1w; > } > > Kind regards, > > Karl > > > Nope, since the request actually processed by your PHP handler not at that location. Since it's an fcgi, pretty sure caching directives only work with fastcgi_cache: http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_cache_valid > > > On Tue, Mar 17, 2015 at 2:02 PM, Nurahmadie Nurahmadie < > nurahma...@gmail.com> wrote: > >> That's because the latter regex location takes precedence over the >> /static one. >> You should first decide if that regex location should also includes >> /static prefix or not. >> If it's a yes, then you should also add the same rewrite-rule inside your >> regex location, if it's a not, you can turn your /static location to also >> use regex like this >> >> location ~ ^/static/ { >> # rewrite here... >> } >> >> So nginx will take a look at that location first when you request for >> /static/* urls. >> >> Another way is to use `try_files`, but then you should probably create >> another (internal) location block to do the rewrite. >> >> >> On Wed, Mar 18, 2015 at 2:49 AM, Karl Johnson <karljohnson...@gmail.com> >> wrote: >> >>> Hello, >>> >>> I host a website based on Laravel with Nginx 1.6.2 + PHP-FPM 5.6. Most >>> images on the website are in /static folder and are served to visitors with >>> a PHP file (see /static location). >>> >>> I want to add a 30 days expire on all images of this vhost. However, >>> when I add the "location ~* \.(?:image)$ {" rule to add expire, the rewrite >>> for images in /static doesn't work anymore. Nginx reports file not found >>> for all images in /static. >>> >>> Any idea how to make it works? >>> >>> Vhost configuration below: >>> >>> server { >>> listen 80; >>> server_name www.website.com; >>> root /home/www/website.com/public_html/public; >>> access_log /var/log/nginx/website.com-access_log; >>> error_log /var/log/nginx/website.com-error_log warn; >>> >>> location /static { >>> rewrite ^/static/images/([0-9])\-([0-9]+)x([0-9]+)/(.*)$ >>> /image-f7ec13d.php?zc=$1&w=$2&h=$3&src=../uploads/images/$4; >>> } >>> >>> ## not working, break the rewrite images above >>> # >>> # location ~* >>> \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|woff)$ { >>> # expires 30d; >>> # add_header Cache-Control "public"; >>> # } >>> >>> include conf.d/custom/restrictions.conf; >>> include conf.d/custom/pagespeed.conf; >>> include conf.d/custom/fpm-laravel.conf; >>> >>> pagespeed DisableFilters combine_css; >>> } >>> >>> >>> Rewrite not working after adding the location for all images expire: >>> >>> 2015/03/17 13:46:12 [error] 11792#0: *12217 openat() "/home/www/ >>> website.com/public/static/images/0-0x0/2015/03/2015-03-10-media-fr.jpg" >>> failed (2: No such file or directory) >>> >>> >>> >>> Regards, >>> >>> Karl >>> >>> _______________________________________________ >>> nginx mailing list >>> nginx@nginx.org >>> http://mailman.nginx.org/mailman/listinfo/nginx >>> >> >> >> >> -- >> regards, >> Nurahmadie >> -- >> >> _______________________________________________ >> nginx mailing list >> nginx@nginx.org >> http://mailman.nginx.org/mailman/listinfo/nginx >> > > > _______________________________________________ > nginx mailing list > nginx@nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx > -- regards, Nurahmadie --
_______________________________________________ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx