Opened 3 years ago

Closed 3 years ago

#1313 closed task (invalid)

If "return" rules are above than "expires", then "expires" stop working.

Reported by: nonegit@… Owned by:
Priority: major Milestone:
Component: nginx-core Version: 1.10.x
Keywords: Cc: pkg-nginx-maintainers@…
uname -a: Linux NGX 4.9.0-3-686-pae #1 SMP Debian 4.9.30-2+deb9u2 (2017-06-26) i686 GNU/Linux
nginx -V: nginx version: nginx/1.10.3
built with OpenSSL 1.1.0d 26 Jan 2017 (running with OpenSSL 1.1.0f 25 May 2017)
TLS SNI support enabled

Debian's latest
packages.debian.org/stretch/nginx-extras

Description

server{
...
[1] location ~* \.(css|js|jpg|zip)$ {valid_referers server_names;if ($invalid_referer){return 444;}}
[2] location ~ /customer/downloads/ {valid_referers server_names;if ($invalid_referer){return 444;}}
[3] location ~* \.(css|html|js|jpg)$ {expires 2h;}
...
}

Current result:
/customer/downloads/ (=index.html) --- returns "Cache-Control: max-age=7200" header
/customer/downloads/xxx.css,
/customer/downloads/xxx.jpg --- doesn't return Cache header

Expected result:
/customer/downloads/xxx.css,
/customer/downloads/xxx.jpg must return cache control header, like html.

Why is this happening?

Note:

  1. If I move [3] to above [1], [1] and [2] rules are completely ignored.

Change History (2)

comment:1 by nonegit@…, 3 years ago

nginx processing

Expected result:

  1. Ok, next line.
  2. Referer is okay, we won't return 444.
  3. Ok, next line please.
  4. Set expires to these extensions. Got it.

Actual result:

  1. Ok, next line.
  2. Referer is okay, we won't return 444.
  3. Ok, next line please.
  4. What's this? Set expire header? We decided to return not-444, nothing more!!

comment:2 by Maxim Dounin, 3 years ago

Resolution: invalid
Status: newclosed

Consider reading How nginx processes a request and documentation on the location directive. In the example above, /customer/downloads/xxx.jpg request is matched by the location ~* \.(css|js|jpg|zip)$ location, which does not contain the expires directives. As such, the result is expected.

If you have further questions on how to use nginx, consider support options available.

Note: See TracTickets for help on using tickets.