I have the following nginx configuration fragment:
server { listen 80; server_name mydomain.io; root /srv/www/domains/mydomain.io; index index
On the first question - simply add both domains:
server_name mydomain.io www.mydomain.io;
For the second, you'll need this simple redirect:
server { listen 80; server_name www.mydomain.io mydomain.io; if ($host = 'www.mydomain.io' ) { rewrite ^/(.*)$ http://mydomain.io/$1 permanent; }