title: Nginx: rewrite rule to redirect to https page
body: <p>I want to redirect my login page to https so that users do not inadvertently enter their credentials through the unencrypted network.  How do I do something like the below?</p>
  
  <pre><code># nginx.conf
  server {
    server_name example.org;
    rewrite http://*.example.org/login https://example.org/login;
  }
  </code></pre>
  
  <p>This works for <a href="http://example.org/login" rel="nofollow">http://example.org/login</a>, but it does not work for <a href="http://www.example.org/login" rel="nofollow">http://www.example.org/login</a></p>
  
  <p>Rewrite rule output for</p>
  
  <pre><code>rewrite http://.*\.?example.org/login https://example.org/login;
  </code></pre>
  
  <p>Rewrite debug output:</p>
  
  <pre><code>*2 "http://.*\.?example.org/login" does not match "/login", client: XXX.XXX.XX.72, server: example.org, request: "GET /user HTTP/1.1", host: "example.org"
  </code></pre>