add_header cache-control "no-cache, no-store"; 这条配置的整体作用是,向HTTP响应头中添加 Cache-Control 字段,并设置其值为 no-cache, no-store。这样做会确保浏览器或其他缓存系统不会缓存该响应,每次请求时都需要从服务器重新获取数据。 配置示例或实际应用场景: 配置示例(Nginx配置): ngin
add_header Cache-Control no-store add_header Content-Encoding gzip 但是有一个十分常用的response header比较特性,就是Content-Type,可以在它设置了类型的同时还会指定charset,例如:“text/html; charset=utf-8”,由于其存在分号,而分号在配置文件中作为结束符,所以在配置的时候需要用引号把其引起来,配置如下: 复...
location中的if模块--没有返回自定义add_header 将静态资源(css、js)设置为强缓存,将html文件设置为协商缓存,cache-control:no-cache,避免html也被缓存,导致用户不能及时更新最新的内容 # cat /usr/share/nginx/html/1.jstest# cat /etc/nginx/nginx.confserver { listen 80; listen [::]:80; server_name...
通过添加一些缓存相关的HTTP响应头部,可以控制浏览器和代理服务器对静态资源的缓存行为。例如,可以使用add_header指令添加Cache-Control字段来指定缓存策略,使用Expires字段来设置资源的过期时间。 设置自定义的HTTP响应头部 除了安全和缓存相关的HTTP响应头部,add_header指令还可以用于添加自定义的字段和值。这些自定义的...
Cache-Control 此头部用于控制缓存行为,告诉浏览器和中间代理如何缓存资源。 Nginx add_header Cache-Control "public, max-age=31536000"; 3、API控制 Access-Control-Allow-Origin Nginx add_header Access-Control-Allow-Origin "*"; Access-Control-Allow-Methods ...
缓存控制头:如Cache-Control,Expires。 安全头:如X-Frame-Options,Strict-Transport-Security,Content-Security-Policy。 自定义头:用于传递特定于应用的信息。 示例配置 代码语言:txt 复制 server { listen 80; server_name example.com; location / { add_header Cache-Control "public, max-age=3600"; add_hea...
add_header Cache-Controlprivate; location /yp { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://192.168.0.221:8082/yp/yp; ...
add_header Cache-Control "max-age=3600, public"; # 其他配置... } } proxy_set_header proxy_set_header 则是在 Nginx 将请求转发给后端服务器之前设置 HTTP 请求头。它的主要用途是将某些客户端信息或者自定义信息传递给后端服务,例如客户端的真实 IP 地址、HTTP 方法等。
例如,你可以使用`add_header Cache-Control`指令来指定缓存策略。 location / { add_header Cache-Control "public, max-age=3600"; ... }复制代码 3. 安全性设置: `add_header`指令还可以用于增强服务器的安全性。例如,可以添加`Strict-Transport-Security`头部字段来启用严格的传输安全机制(HTTP Strict ...
add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0' 发送一个报头,告诉浏览器当前页面不进行缓存,每次访问的时间必须从服务器上读取最新的数据 一般情况下,浏览器为了加快浏览速度会对网页进行缓存,在一定时间内再次访问同一页面的时候会有缓存里面读取而不是从服务...