'Chooses a virtual host based on the given domain name.
.. note:: This makes the vhost SSL-enabled if it isn\'t already. Follows
Nginx\'s server block selection rules preferring blocks that are
already SSL.
.. todo:: This should maybe return list if no obvious answer
is presented.
.. todo:: The special name "$hostname" corresponds to the machine\'s
hostname. Currently we just ignore this.
:param str target_name: domain name
:returns: ssl vhost associated with name
:rtype: :class:`~certbot_nginx.obj.VirtualHost`'

def choose_vhost(self, target_name):

    vhost = None
    matches = self._get_ranked_matches(target_name)
    vhost = self._select_best_name_match(matches)
    if (not vhost):
        raise errors.MisconfigurationError(('Cannot    find    a    VirtualHost    matching    domain    %s.' % target_name))
    elif (not vhost.ssl):
        self._make_server_ssl(vhost)
    return vhost
