内容分发网络CDN

    加速域名配置

    设置回源地址

    public void setDomainOrigin(CdnClient client, String domainName) {
        String hostAddress = “origin.my.com”; // 源站地址
        String hostName = “my.com”; // 回源Host,不配置则默认使用加速域名
     
        List<OriginPeer> origin = new ArrayList<OriginPeer>();
        origin.add(new OriginPeer().withPeer(hostAddress).withHost(hostName));
        SetDomainOriginRequest request = new SetDomainOriginRequest()
                .withDomain(domainName)
                .withOrigin(origin);
        client.setDomainOrigin(request);
    }

    设置缓存策略

    public void setDomainCacheTTL(CdnClient client, String domainName) {
        SetDomainCacheTTLRequest request = new SetDomainCacheTTLRequest()
                .withDomain(DOMAIN)
                .addCacheTTL(new CacheTTL().withType("suffix").withValue(".jpg").withTtl(3600)) // .jpg后缀缓存一小时
                .addCacheTTL(new CacheTTL().withType("suffix").withValue(".png").withTtl(3600)) // .png后缀缓存一小时
                .addCacheTTL(new CacheTTL().withType("path").withValue("/").withTtl(86400));    // 根目录缓存一天
        client.setDomainCacheTTL(request);
    }

    设置全url缓存

    public void setDomainCacheFullUrl(CdnClient client, String domainName) {
        client.setDomainCacheFullUrl(domainName, true);
    }

    设置访问Referer控制

    public void setDomainRefererACL(CdnClient client, String domainName) {
        RefererACL acl = new RefererACL()
                .addBlackList("http://a.com")
                .addBlackList("http://b.com");
        SetDomainRefererACLRequest request = new SetDomainRefererACLRequest()
                .withDomain(DOMAIN)
                .withRefererACL(acl);
        cdnClient.setDomainRefererACL(request);
    }

    设置访问Ip控制

    public void setDomainIpACL(CdnClient client, String domainName) {
        IpACL acl = new IpACL()
                .addBlackList("1.2.3.4")
                .addBlackList("5.6.7.0/24");
        SetDomainIpACLRequest request = new SetDomainIpACLRequest()
               .withDomain(domainName)
               .withIpACL(acl);
        client.setDomainIpACL(request);
    }
    上一篇
    加速域名管理
    下一篇
    缓存管理