简体   繁体   English

管理Catalyst / Nginx中的缺失图像

[英]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. 在Catalyst调试器中,我可以看到它们显示为404,并带有错误的完整描述。
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? 我正在使用Nginx,所以...如果它们是静态目录中的静态文件,它们不应该由Nginx而不是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? 第二:如果在将图片文件发送到模板之前图片文件是否存在,它是否可以更好地在Catalyst中进行测试?
There will be more nonexistent pictures that existent ones. 将存在更多不存在的图片。

Thanks:Migue 感谢:Migue

You need to configure nginx to handle your static files, instead of passing the requests to Catalyst. 您需要配置nginx来处理静态文件,而不是将请求传递给Catalyst。 For example, if you put all your static files (images, Javascript, css, etc.) in root/static/, your nginx configuration should include: 例如,如果您将所有静态文件(图像,Javascript,css等)放在root / static /中,您的nginx配置应包括:

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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