0

I am trying to set a dynamic expires header. This is basically my config:

# http context
map $request_uri $expires_time {
 
   default -1;
 
   *.js max;
}

server {
  # server_name/proxy_headers/listen/ssl
  location / {
    
    expires $expires_time;
    proxy_pass http_serverving_docker_container.docker;
  }
}

I am getting this error message on a nginx -t:

nginx: [emerg] "expires" directive invalid value in /etc/nginx/sites-enabled/config:57 # <- this is the expires line
nginx: configuration file /etc/nginx/nginx.conf test failed

If I exchange it with a number (e.g.: -1), then everything works perfectly fine. Am I not allowed to use variables here? I perused the manual page for expires and haven't seen a mention of that.

Additional information: Nginx version: nginx/1.6.2 Linux version: Debian GNU/Linux 8 (jessie)

1 Answers1

1

You're using an obsolete version of nginx on an obsolete Linux distribution. Both need to be upgraded ASAP.

In particular:

  • Debian 8 is past end of LTS support. It receives no further updates, not even security updates. It is an extreme risk to have this system connected to the Internet.
  • As the documentation states, using a variable in the nginx expires directive requires at least version 1.7.9.
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
  • I have completely overlooked this sentence: `The last parameter value can contain variables (1.7.9)` That explains it. Thank you. Sadly, updating it will not be up to me. – TheCommoner282 Feb 12 '21 at 06:43