简体   繁体   中英

Manage missing images in Catalyst/Nginx

in my app there are a lot of pictures that can be missing or lost. A lot of them.
In the Catalyst debugger I can see that they are shown as 404, with a full description of the error.
I am using Nginx, so... if they are static files in the static directory, aren't they supposed to be managed by Nginx instead of Catalyst?
And second: can it be a better approach to test in Catalyst if the picture file exists or not before send it to the template?
There will be more nonexistent pictures that existent ones.

Thanks:Migue

You need to configure nginx to handle your static files, instead of passing the requests to Catalyst. For example, if you put all your static files (images, Javascript, css, etc.) in root/static/, your nginx configuration should include:

location /static {
    alias /home/user/MyApp/root/static/;
    expires 30d;
}

Then you can return a specific image when it is not found:

location /static/images {
     root /home/user/MyApp/root/static/images;
     error_page  404 /not_found.gif;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM