【问题标题】:Html files cached regardless of nginx configuration无论 nginx 配置如何,都会缓存 Html 文件
【发布时间】:2016-10-04 01:37:03
【问题描述】:

我采用了最基本的 nginx.conf 示例,并尝试在 html 文件上添加无缓存控件。尝试了我发现的所有东西,似乎没有任何效果。这是我目前的配置文件

user  nobody;
worker_processes  3;

pid logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    server {
        listen       80;
        listen      [::]:80;

        location / {
            location ~\/.+ {
                root /var/www;
                index index.html index.htm;
            }

            location ~* \.html$ {
               expires -1;
            }
        }
    }
}

我的问题是我做错了什么是因为 nginx 还是因为其他原因?

【问题讨论】:

    标签: caching nginx


    【解决方案1】:

    您的配置存在多个问题。您定义了一个 location ~* \.html$ 块,但没有定义 root。您还不必要地嵌套了位置块。

    试试这样的:

    root /var/www;
    index index.html index.htm;
    
    location / {
    }
    
    location ~* \.html$ {
        expires -1;
    }
    

    rootindex 指令在 server 块级别定义,由所有位置块继承。

    有关详细信息,请参阅 the root directivethe location directive。另外,how nginx processes a request 的概述。

    【讨论】:

      猜你喜欢
      • 2017-10-30
      • 2014-10-28
      • 1970-01-01
      • 1970-01-01
      • 2019-02-11
      • 1970-01-01
      • 2021-02-09
      • 2015-05-19
      • 2013-11-07
      相关资源
      最近更新 更多