www in domain not working in nginx
You are rewriting www.domain.com on first few lines of nginx.conf. If i'm not wrong, rewriting and redirecting are different things. Try this on first server block;
server { server_name www.mydomain.com; return 301 http://mydomain.com$request_uri;}
and change
server_name mydomain.com www.mydomain.com
to
server_name mydomain.com
in second server block.