0

I use nginx to proxy another nginx server, but there is somethine wrong about cache. The config file of proxied server (backend server) :

 location ~* .*\.(gif|jpg|jpeg|bmp|png|ico|txt|pdf|doc|docx|xls|xlsx|ppt|pptx|vtt)$
        {
                include conf.d/open_file.conf;
                include conf.d/static.conf;
                expires      4d;
        }

It set the pdf file expires after 4 days. But I use proxy_ignore_headers in proxy server:

location ^~ /pk/ {
                    proxy_pass http://pk_server/;
                    if ($request_method = 'OPTIONS' ) {
                            return 403;
                    }
                    proxy_http_version 1.1;
                    proxy_set_header Connection "";
                    proxy_set_header   Host    $http_host;
                    proxy_set_header   Remote_Addr    $remote_addr;
                    proxy_set_header   X-Real-IP    $remote_addr;
                    proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;
                    #proxy_set_header   X-Forwarded-Proto  $scheme;
                    if ($http_x_forwarded_proto != '') {
                            set $final_scheme $http_x_forwarded_proto;
                    }
                    if ($http_x_forwarded_proto = '') {
                            set $final_scheme $scheme;
                    }
                    proxy_set_header X-Forwarded-Proto $final_scheme;
                    proxy_set_header Cookie $http_cookie;
                    proxy_set_header Cache-Control 'no-cache';
                    proxy_ignore_headers "Expires" "Cache-Control";
                    if ($args ~* nocache=) {
                            set $arg_nocache 1;
                    }
                    if ($request_uri ~* \.mp4$) {
                            set $arg_nocache 1;
                    }
                    proxy_cache ava_cache;
                    proxy_cache_valid 200 302 301 304 90s;
                    proxy_cache_key $host$uri$is_args$args;
                    add_header X-Cache $upstream_cache_status;
                    add_header X-Frame-Options SAMEORIGIN;
                    add_header Access-Control-Allow-Methods GET,POST,HEAD;
         }

But when I request a pdf file, the respone header has expires and the browser get pdf from disk cache after first request:
request info

How could I do to let the browser to use If-Modified-Since to check if the file has been modified instead of read from disk cache

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.