How to exclude .well-known folder when upgrade?

Adding to what @tflidd correctly explained I would avoid the syntax of the first and third location lines, because locations preceded by a ~ are regular expressions. And in regular expressions / need to be escaped.

Assuming that /* is meant to be \/.* and not \/* (which in my opinion doesn’t make any sense) the first and third location lines should be:
location ~ ^\/\.well-known\/acme-challenge\/.* {
and
location ~ ^\/\.well-known\/acme-challenge\/ {
Those two lines would actually match the same requests.

The ^~ before the second location block means, that the location is not a regular expression, but a prefix string with a special meaning: if a request matches this prefix string, location blocks with regular expressions won’t be tested.

So if all three lines would reside in the same nginx server block, requests starting with /.well-known/acme-challenge/ would all be served by the second location block (regardless of the order of the three location blocks!). Here is what the nginx docu says about location blocks: https://nginx.org/en/docs/http/ngx_http_core_module.html#location

There is also a very good article at digitalocean about location blocks in nginx:

Hope that helps! Cheers, Bernie_O

1 Like