如何配置Nginx不缓存特定的URL?

问题描述 投票:1回答:2

我有一个Nginx服务器作为前端缓存服务器,我想在特定网址上禁用缓存。

这是Nginx上的配置:

proxy_cache_path /tmp/nginx levels=1:2 keys_zone=my_zone:10m  inactive=120m max_size=1000m;
proxy_cache_key "$scheme$request_method$host$request_uri$is_args$args";

server {
  listen       10.0.0.45:80 default_server;
  server_name  proxy2.jjd;
  include      /etc/nginx/default.d/*.conf;
  location / {

    client_max_body_size 20m;
    proxy_cache my_zone;
    proxy_cache_bypass  $http_cache_control;

    proxy_no_cache $http_pragma $http_authorization $cookie_nocache $arg_nocache;

    add_header      X-Proxy-Cache-NGINX $upstream_cache_status;
    add_header      X-Real-IP $remote_addr;
    add_header      Cache-Control "public";
    proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header      X-Forwarded-Proto https;
    proxy_set_header      X-Forwarded-Port 443;
    proxy_set_header      Host $host;

    proxy_pass            http://127.0.0.1:8080;
    proxy_read_timeout    90;
    proxy_connect_timeout 90;
    proxy_redirect        off;
  }
}
nginx cache-control
2个回答
0
投票

添加以下位置以避免网址:

location ^~ /your-url/ {
    add_header            X-Real-IP $remote_addr;

    proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header      X-Forwarded-Proto https;
    proxy_set_header      X-Forwarded-Port 443;
    proxy_set_header      Host $host;

    proxy_pass            http://127.0.0.1:8080;
    proxy_read_timeout    90;
    proxy_connect_timeout 90;
    proxy_redirect        off;
}

它只是将此位置分配给代理,并且不为其启用缓存。


-1
投票

你只需指定位置do proxy_pass只用于禁用缓存

location / will / not / cache {proxy_pass http://127.0.0.1:8080; ..set_header ..}

© www.soinside.com 2019 - 2024. All rights reserved.