Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么nginx不缓存扩展名为.html的脚本?_Php_Apache_Caching_Nginx - Fatal编程技术网

Php 为什么nginx不缓存扩展名为.html的脚本?

Php 为什么nginx不缓存扩展名为.html的脚本?,php,apache,caching,nginx,Php,Apache,Caching,Nginx,我有nginx/1.4.2+Apache,我想用nginx缓存所有请求。此位置规则为.php而不是.html创建缓存文件: location ~* \.(html|php)$ { proxy_pass http://127.0.0.1:8080; proxy_set_header Host my-host-name.com; proxy_set_header X-Forwarded-For $proxy_add_x_

我有nginx/1.4.2+Apache,我想用nginx缓存所有请求。此位置规则为.php而不是.html创建缓存文件:

    location ~* \.(html|php)$ {
            proxy_pass http://127.0.0.1:8080;
            proxy_set_header Host my-host-name.com;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;

            add_header cache "html";

            proxy_cache default;
            proxy_cache_min_uses 1;
            proxy_cache_valid  1d;
            proxy_cache_key "$host|$request_uri";
            proxy_hide_header "Set-Cookie";
            proxy_ignore_headers "Cache-Control" "Expires";
    }
响应中添加了标题“缓存”,所以位置正常

我尝试过使用“location/”—对缓存中存储有.php扩展名(不带任何扩展名)的脚本的请求。对于扩展名为.html的脚本,nginx不创建缓存


我找不到nginx忽略扩展名为.html的脚本的原因。将脚本重命名为.php-这不是方法。我有CMS,它可以为带有.html的页面创建人类可读的URL,Google索引中有数千个页面,现在重命名将导致站点重新索引。

可能是因为您的CMS返回
设置Cookie
标题。

是的!因为在配置中我有:proxy\u hide\u头“Set Cookie”;所以,在nginx之后,我们看不到“Set Cookie”头是否存在。如果CMS尝试发送cookies,nginx将禁用缓存