Nginx,关闭特定文件的缓存

Nginx, turn off cache for a specific file

location /static {
    alias /home/ubuntu/Documents/zibann/momsite/momsite/static; # your Django project's static files - amend as required
    if ($uri ~* ".*config.js") {
       expires off;
    }

    if ($uri ~* ".*\.(js|css|png|jpg|jpeg|gif|swf|svg)" ) {
       access_log off;
       expires 365d;
       add_header Cache-Control public;
    }

}

希望 config.js 不会被缓存,但确实如此。
如何排除一个文件被缓存?

为 config.js 创建一个单独的位置块。

location ~ config\.js {
    alias xyz;
    expires off;
}

location static etc

我尝试了上面和其他页面中的所有示例。唯一对我有用的就是这个。我的文件是 PHP,我必须创建配置文件最后一部分的完整副本。也许替换 location ~ config.js 对你也有用。

location ~ player\.php {
        set $no_cache 1;
            fastcgi_index  index.php;
            include        fastcgi_params;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;   
            if (-f $request_filename) {
                # Only throw it at PHP-FPM if the file exists (prevents some PHP exploits)
                fastcgi_pass   unix:/tmp/run/php7-fpm.sock;
                #fastcgi_read_timeout 3600;
            }         
}