无论nginx配置如何缓存Html文件
问题描述:
我采用了最基本的nginx.conf示例,并尝试在html文件中添加no-cache控件。尝试了我找到的一切,似乎没有任何工作。这是我目前的配置文件无论nginx配置如何缓存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还是因为别的东西?
答
您的配置有多个问题。您已经定义了一个location ~* \.html$
块,没有定义root
。您还不必要地嵌套位置块。
尝试这样:
root /var/www;
index index.html index.htm;
location/{
}
location ~* \.html$ {
expires -1;
}
的root
和index
指令是在server
块级别定义为所有位置块继承。
有关更多详细信息,请参见the root
directive和the location
directive。另外,这个概述how nginx
processes a request。