title: nginx dynamic HTTP/S resolves to https://_
body: <p>I'm trying to let all traffic for my nginx be redirected to HTTPS, independent of server name. So, any other vhost should be redirected to its HTTPS counterpart. </p>
  
  <p>example.com -> <a href="https://example.com" rel="nofollow noreferrer">https://example.com</a><br>
  test.com -> <a href="https://test.com" rel="nofollow noreferrer">https://test.com</a><br>
  ...</p>
  
  <p>Yet, instead of using the incoming <code>$server_name</code> or <code>$host</code> (tried both), it keeps redirecting to a plain <code>https://_</code>. Is my config incorrect?</p>
  
  <pre><code>server {
    listen        80 default_server;
    listen        [::]:80 default_server;
    server_name   _;
    return        301 https://$server_name$request_uri;
  }
  </code></pre>