I use `return` whenever the whole job is sending visitors somewhere else, since no regex is involved.
server { listen 80; server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}
return stops processing at once and sends the response, which is faster and easier to read than rewrite ^ ... permanent. $request_uri carries the original path and query string along. Browsers cache a 301 very hard, so start with 302 while testing and switch when it is right. A second server block for the https site then handles the real content. curl -I http://example.com/x?y=1 shows the Location header you will get.
Further reading: ngx_http_rewrite_module: return
Going deeper: Run degoog on Unraid as your own search page, compared with SearXNG and 4get