Domain configuration in nginx config

Redirect www.mydomain.com to mydomain.com:

server {
    server_name www.mydomain.com;
    return 301 http://domain.com$request_uri;
}

server {
    server_name mydomain.com;
    # The rest of your configuration goes here
}

Dot at the end of site domain can cause problems.

server {
    server_name mydomain.com;
    if ($http_host ~ "\.$" ) {
        return 301 http://mydomain.com$request_uri;
    }
    # The rest of your configuration goes here
}

For old nginx versions:

- return 301 http://mydomain.com$request_uri;
+ rewrite  ^/(.*)$  http://mydomain.com/$1 permanent;

Links:

Licensed under CC BY-SA 3.0