Хосты в nginx с ssl?
Получилось решить проблему примерно следующим конфигом:
site.com - онли хттпсserver {
        listen 80 default_server;
        server_name www.site.com site.com;
        access_log /var/www/site.com/logs/nginx.access_log;
        error_log /var/www/site.com/logs/nginx.error_log;

        return 301 https://site.com$request_uri;
}

server {
        listen 443 ssl;
        server_name www.site.com;
        access_log /var/www/site.com/logs/nginx.access_log;
        error_log /var/www/site.com/logs/nginx.error_log;

        ssl on;
        ssl_certificate /etc/nginx/ssl/site.com.compiled.crt;
        ssl_certificate_key /etc/nginx/ssl/site.com.key;

        return 301 https://site.com$request_uri;
}

server {
        listen 443 default_server ssl;
        server_name site.com;

        access_log /var/www/site.com/logs/nginx.access_log;
        error_log /var/www/site.com/logs/nginx.error_log;

        root /var/www/site.com/public_html;
        index index.html index.htm;

        ssl on;
        ssl_certificate /etc/nginx/ssl/site.com.compiled.crt;
        ssl_certificate_key /etc/nginx/ssl/site.com.key;

        location / {
                try_files $uri $uri/ =404;
                fastcgi_param  HTTPS on;
        }
}
и второй, тестовый хостserver {
        listen 443 ssl;
        server_name www.dev.site.com dev.site.com;
        access_log /var/www/dev.site.com/logs/nginx.access_log;
        error_log /var/www/dev.site.com/logs/nginx.error_log;

        return 301 http://dev.site.com$request_uri;
}

server {
        listen 80;
        server_name www.dev.site.com;
        access_log /var/www/dev.site.com/logs/nginx.access_log;
        error_log /var/www/dev.site.com/logs/nginx.error_log;

        return 301 http://dev.site.com$request_uri;
}

server {
        listen 80;
        server_name dev.site.com;

        access_log /var/www/dev.site.com/logs/nginx.access_log;
        error_log /var/www/dev.site.com/logs/nginx.error_log;

        root /var/www/dev.site.com/public_html;
        index index.html index.htm;

        location / {
                try_files $uri $uri/ =404;
        }
}
Блоки с if{...} – зло. Чтобы только SSL и только без www, пропишите отдельными конфигами вспомогательные редиректы:#   Ловит всех по http
server {
    listen 80;
    server_name    site.com  www.site.com;
    return 301 https://site.com$request_uri;
}

#   Только https, с лишним www.
server {
    listen 443 ssl;
    server_name    www.site.com;
    return 301  https://site.com$request_uri;
}
Аналогично для тестового пропишите.