nginx - which way is better to redirect and why

Second way is better...

server {
  listen   80;
  server_name  www.domain.com;
  return 301 $scheme://domain.com$request_uri;
}

Why

Let me quote directly from the official Nginx wiki at Pitfalls and Common Mistakes:

By using the built-in variable $request_uri, we can effectively avoid doing any capturing or matching at all, and by using the return directive, we can completely avoid evaluation of regular expression.

My own thoughts...

By default, the regex is costly and will slow down the performance.