server {
server_name www.mydomain.com;
listen 80;
return 301 http://mydomain.com$request_uri;
}
server {
server_name www.mydomain.com;
listen 80;
if ($http_host = www.mydomain.com) {
rewrite ^(.*)$ http://mydomain.com$1 permanent;
}
}
server_name site.com www.site.com
listen 1.2.3.4;
if ($host ~* www\.(.*)) {
set $host_without_www $1;
rewrite ^(.*)$ http://$host_without_www$1 permanent;
}