Adding expires on all images break nginx rewrite

Karl Johnson at
Tue Mar 17 17:49:33 UTC 2015


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;
        root /home/www/;
        access_log /var/log/nginx/;
        error_log /var/log/nginx/ warn;

        location /static {
                rewrite ^/static/images/([0-9])\-([0-9]+)x([0-9]+)/(.*)$

## 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/"
failed (2: No such file or directory)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list