#Add server block as bellow to redirect yourolddomin.com to yournewdomain.com
#Redirect subdomain "mail.yourdomain.com" to subfolder "yourdomain.com/mail"
server {
listen 80;
server_name yourolddomain.com;
return 301 $scheme://yournewdomain.com$request_uri;
}
#To redirect folder to subdomain
#If want to redirect permanently, change "redirect" to "permanent"
rewrite ^/images/(.*)$ http://images.example.com/$1 redirect;