if ($http_user_agent ~* "Baiduspider|360spider|360Spider|YisouSpider|spider|bot") {
    set $ssl "y";
}

if ($http_user_agent ~* "Windows\ NT\ 5.1|Windows\ NT\ 5.2") {
    set $ssl "n";
}


if ($scheme = 'http' ) {
    set $ssl "${ssl}es";
}

if ( $ssl = "yes" ) {
    rewrite ^(.*)$ https://$host$1 permanent;
}
