简体   繁体   English

Nginx FastCGI用于jpg + gif + png缓存

[英]Nginx FastCGI for jpg + gif + png caching

Looking at how nginx-fastCGI can be used for caching in a php app, I see the following 查看如何将nginx-fastCGI用于php应用程序中的缓存,我看到以下内容

location ~ ^(.+\.php)(.*)$ {
    fastcgi_split_path_info       ^(.+\.php)(.*)$;
    fastcgi_param SCRIPT_FILENAME /path/to/php$fastcgi_script_name;
    fastcgi_param PATH_INFO       $fastcgi_path_info;
}

If this were a python app, life would be much simpler, but I don't always get to choose what I work with. 如果这是一个python应用程序,那么生活会简单得多,但我并非总能选择要使用的工具。 I'd like to limit the caching above to only static assets, like .jpg, et. 我想将上述缓存限制为仅静态资产,例如.jpg等。 al.

In a python/django world, I could so something like 在python / django世界中,我可以这样

location /static/$ {
    fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    fastcgi_param PATH_INFO       $fastcgi_path_info;
}

What I think I can do is 我能做的是

location ~ ^(*.jpg|*.png|*.gif)$ {
    fastcgi_param SCRIPT_FILENAME /path/to/php$fastcgi_script_name;
    fastcgi_param PATH_INFO       $fastcgi_path_info;
}

One more thing to mention. 还有一件事要提。 The static file are not in a single static directory, rather mixed in with other directories..Hence the problem. 静态文件不在单个static目录中,而是与其他目录混合。

Will that work? 那行得通吗? Anyone have a good way of doing this? 有人有这样做的好方法吗?

Create a separated location block for the static files: 为静态文件创建一个单独的位置块:

location ~ ^/(static/) {
    root /path/to/the/static/dir;
    expires max;
}

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

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