内容分发网络CDN

    加速域名配置

    查询加速域名详情接口

    public void testGetDomainConfig() {
            String domain="vd3.bdstatic.com";
            GetDomainConfigResponse response = cdnClient.getDomainConfig(domain);
            System.out.println(response);
        }

    设置HTTPS加速

      public void testSetHttpsConfig() {
            String domain="imagete11.changxin.com";
            HttpsConfig https = new HttpsConfig()
                    .withEnabled(true)
                    .withCertId("cert-id");
            SetHttpsConfigRequest request = new SetHttpsConfigRequest()
                    .withDomain(domain)
                    .withHttps(https);
            cdnClient.setHttpsConfig(request);
        }

    设置回源地址

    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);
    }

    设置IP访问限频

        public void setAccessLimit(){
            String domain="vd3.bdstatic.com";
            AccessLimit accessLimit=new AccessLimit().withEnabled(true).withLimit(200);
            SetAccessLimitResponse response = cdnClient.setAccessLimit(domain, accessLimit);
            System.out.println(response);
        }
    上一篇
    加速域名管理
    下一篇
    缓存配置接口