'Add or replace directives in the server block identified by vhost.
This method modifies vhost to be fully consistent with the new directives.
..note :: If replace is True and the directive already exists, the first
instance will be replaced. Otherwise, the directive is added.
..note :: If replace is False nothing gets added if an identical
block exists already.
..todo :: Doesn\'t match server blocks whose server_name directives are
split across multiple conf files.
:param :class:`~certbot_nginx.obj.VirtualHost` vhost: The vhost
whose information we use to match on
:param list directives: The directives to add
:param bool replace: Whether to only replace existing directives'

def add_server_directives(self, vhost, directives, replace):

    filename = vhost.filep
    try:
        result = self.parsed[filename]
        for index in vhost.path:
            result = result[index]
        if ((not isinstance(result, list)) or (len(result) != 2)):
            raise errors.MisconfigurationError('Not    a    server    block.')
        result = result[1]
        _add_directives(result, directives, replace)
        new_server = self._get_included_directives(result)
        parsed_server = self.parse_server(new_server)
        vhost.addrs = parsed_server['addrs']
        vhost.ssl = parsed_server['ssl']
        vhost.names = parsed_server['names']
        vhost.raw = new_server
    except errors.MisconfigurationError as err:
        raise errors.MisconfigurationError(('Problem    in    %s:    %s' % (filename, str(err))))
