title: Force www. and https in nginx.conf (SSL)
body: <p>After purchasing a SSL certificate I have been trying to force all pages to secured https and to www. </p>
  
  <p><a href="https://www.exampl.com">https://www.exampl.com</a> is working and secure but only if type it in exactly. www.example.com or example.com are still pointing to http.</p>
  
  <p>We use nginx as a proxy and need to input the rewrite there. I have SSH / root access via Putty. I have accessed nginx.conf by inputting into putty.</p>
  
  <p><em>Now what? Do I input the nginx commands on this page? Starting where the cursor is? Any command lines first?</em></p>
  
  <p><strong>HTTPS:</strong></p>
  
  <p><strong>.htacess –</strong> <em>Original code I was given before I found out I had to input into nginx</em></p>
  
  <pre><code>RewriteEngine On 
  RewriteCond %{HTTP_HOST} ^example.com [NC]
  RewriteCond %{SERVER_PORT} 80 
  RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
  </code></pre>
  
  <p><strong>Nginx code converter –</strong> <em>This is how it shows on the converter. Is everything on the correct lines?</em></p>
  
  <pre><code># nginx configuration location / {
  if ($http_host ~* "^example.com"){
  rewrite ^(.*)$ http://example.com/$1 redirect; } }
  </code></pre>
  
  <p>and then </p>
  
  <p><strong>WWW</strong></p>
  
  <p><strong>.htacess –</strong> <em>Original code I was given before I found out I had to input into nginx</em></p>
  
  <pre><code>#Force www:
  RewriteEngine on
  RewriteCond %{HTTP_HOST} ^example.com [NC]
  RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]
  </code></pre>
  
  <p><strong>Nginx code converter –</strong> <em>This is how it shows on the converter. Is everything on the correct line?</em></p>
  
  <pre><code># nginx configuration location / { 
  if ($http_host ~* "^example.com"){ 
  rewrite ^(.*)$ http://www.example.com/$1 redirect; } 
  </code></pre>
  
  <p>}</p>
  
  <p>Do I then save? Restart? </p>
  
  <p>Any help would be greatly appreciated. I have been battling this for weeks. My Hosting company helped as far as they could, now I am learning on the fly…. Or should I just stop and hire a developer? $$$</p>
  
  <p>Thanks</p>