I have the following nginx configuration fragment:
server { listen 80; server_name mydomain.io; root /srv/www/domains/mydomain.io; index index
Another way to code it :
if ($http_host ~* "^www\.(.+)$"){ rewrite ^(.*)$ http://%1$request_uri redirect; }
It works even with multiple domain names on the same code.