title: digital ocean redirect non-www to www
body: <p>I'm trying to redirect my domain <code>http://example.com</code> to <code>http://www.example.com</code> on Digital Ocean.</p>
  
  <p>I have A records for both www and @, so the site is accessible at each domain, but the redirect is not working. Here is what I have in my default config file (/etc/nginx/sites-enabled/default):</p>
  
  <pre><code>server {
  listen 80 default_server;
  listen [::]:80 default_server ipv6only=on;
  
  root /var/www/app/deploy/frontend/;
  index index.html index.htm;
  
  # Make site accessible from http://localhost/
  server_name example.com;
  
  location / {
  # First attempt to serve request as file, then
  # as directory, then fall back to displaying a 404.
  try_files $uri $uri/ =404;
  # Uncomment to enable naxsi on this location
  # include /etc/nginx/naxsi.rules
  }
  }
  
  #Redirect example.com to www.example.com
  
  server {
  listen 80;
  server_name example.com;
  return 301 http://www.example.com.io$request_uri;
  }
  </code></pre>
  
  <p>Any ideas?</p>