Você pode substituir o if
por um local normal:
server {
listen 80;
server_name example.com;
location /.well-known/acme-challenge {
root /usr/share/nginx/html;
allow all;
}
location / {
return 301 https://example.com$request_uri;
}
}
Motivo: o local com o maior prefixo correspondente é selecionado e lembrado.
To find location matching a given request, nginx first checks locations defined using the prefix strings (prefix locations). Among them, the location with the longest matching prefix is selected and remembered. Then regular expressions are checked, in the order of their appearance in the configuration file. The search of regular expressions terminates on the first match, and the corresponding configuration is used. If no match with a regular expression is found then the configuration of the prefix location remembered earlier is used.
Fonte: Nginx Docs