I save uploaded image by users into Storage folder with customized path. The image's name will be parsed to know where image will be save in my Storage. Therefore, I write function to return image data when user request image by GET method. It means that image is not get directly. For example, user requests:
I get image name (in this case, d3fe6896b9dcbc02031eaf36761009c6.jpg) and parse it to know where I save the image in Storage folder. Before applying PageSpeed, image is loaded normally. However, image is not found (404 error) after I use PageSpeed for optimizing. I don't modify any PageSpeed Filters (use CoreFilters). My conf in nginx as following:
pagespeed on;
# Needs to exist and be writable by nginx. Use tmpfs for best performance.
pagespeed FileCachePath /var/ngx_pagespeed_cache;
# Ensure requests for pagespeed optimized resources go to the pagespeed handler
# and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
location ~* .(woff|eot|ttf|svg|mp4|webm|jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
When debugging, I see that my code for response image can not reach.
//PHP code
//Parse image name and generate full path
//After that, get image data and response to client
$imageFile = File::get($fullPath);
return response($imageFile, 200)->header('Content-type', 'image/jpeg');
Therefore, I think that PageSpeed fetched image link before my code. As a result, image is not found.
How to solve the problem?