【问题标题】:Nginx FastCGI for jpg + gif + png caching用于 jpg + gif + png 缓存的 Nginx FastCGI
【发布时间】:2016-06-30 04:04:00
【问题描述】:

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

如果这是一个 python 应用程序,生活会简单得多,但我并不总是可以选择我的工作。我想将上面的缓存限制为仅 static 资产,例如 .jpg 等。人。

在 python/django 世界中,我可以这样做

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

我认为我能做的是

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

还有一点要提。静态文件不在单个static 目录中,而是与其他目录混合在一起..因此问题。

这行得通吗?任何人都有这样做的好方法吗?

【问题讨论】:

    标签: php caching nginx fastcgi


    【解决方案1】:

    为静态文件创建一个单独的位置块:

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

    【讨论】:

    • 我应该提到静态文件不在单个目录中。它们与其他内容混合在一起。这是一个 PHP 应用程序 :)
    猜你喜欢
    • 1970-01-01
    • 2021-01-30
    • 2012-12-21
    • 2014-05-31
    • 2011-08-04
    • 2011-07-09
    • 2016-02-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多