N
N
Nikita Shinkevich2021-07-03 15:02:25
Nginx
Nikita Shinkevich, 2021-07-03 15:02:25

What is this setting in NGINX settings?

Hello, there is an nginx vhost config, where it says:

location ~* ^.+\.(css|js)$ {
      root     		"%hostdir%";
      #rewrite ^(.+)\.(\d+)\.(css|js)$ $1.$3 last;
      add_header		Cache-Control "public, max-age=31536000, s-maxage=31536000, no-transform";
    }

Everything is clear to me, except for the line:

rewrite ^(.+)\.(\d+)\.(css|js)$ $1.$3 last;

therefore, it is commented out for now ...

Tell me, what is the function of these parameters?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2021-07-03
@domres

This is a regular expression: ^(.+)\.(\d+)\.(css|js)$
^- the beginning of the line
( )- what is inside the brackets will separately fall into the variables $1, $2, .. $N
.- any character
+- determines the amount of what precedes it: "1 or more"
.+- one or more of any characters
\.- literally an ordinary point, point vulgaris, without special. values
\d​​are a digit. \d+one or more digits
(css|js)- or "css" or "js"
$- the end of the line
Thus, this regular expression will match, say, a string
/css/main.min.682375227.cssand replace it with a string without a number:
/css/main.min.css
Probably, this is how they deal with caching in the browser. In HTML, you can write with any number, and the browser will think it's something new. And the server will always give the same main.min.cssone that it has there.

D
d-stream, 2021-07-03
@d-stream

https://nginx.org/ru/docs/http/ngx_http_rewrite_mo...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question