---
title: "Sitecoreメディアライブラリを手動でCDNを使用するように設定してください"
slug: "manually-configure-the-sitecore-media-library-to-use-a-cdn"
abstract: "Sitecoreメディアライブラリを手動で設定して、Content Delivery Network (CDN)を使えるようにしてください。"
---
# Sitecoreメディアライブラリを手動でCDNを使用するように設定してください

このトピックでは、Sitecoreメディアライブラリを手動で設定し、Microsoft Azure ® Content Delivery Network (CDN)を使えるようにする方法を説明します。これは、既存のオンプレミスまたはAzure展開されたSitecoreインスタンスがあり、SitecoreメディアライブラリにCDNを使わせたい場合に役立ちます。

> !注Azure上で新しいSitecore *XM*インスタンスや*XP scaled*構成をデプロイする場合は、手動で設定する必要はありません。代わりに、以下のいずれかのオプションを使用できます。
> 
> -   [Azure Marketplaceを使ってSitecoreメディアライブラリのCDNを有効にしてください](https://doc.sitecore.com/xp/ja/developers/103/sitecore-experience-manager/use-the-azure-marketplace-to-enable-a-cdn-for-the-sitecore-media-library.html "Use the Azure Marketplace to enable a CDN for the Sitecore Media Library")
>     
> -   [Sitecore Azure Toolkitを使ってSitecoreメディアライブラリのCDNを有効にしてください](https://doc.sitecore.com/xp/ja/developers/103/sitecore-experience-manager/use-sitecore-azure-toolkit-to-enable-cdn-for-the-sitecore-media-library.html "Use Sitecore Azure Toolkit to enable CDN for the Sitecore Media Library")
>     

## 前提条件

SitecoreメディアライブラリをCDNで使用する前に、以下の条件を満たす必要があります:

-   Sitecore XPとXM 9.1以降のバージョンを使用していることを確認してください。
-   [CDNエンドポイントを設定しましょう](https://doc.sitecore.com/xp/ja/developers/103/sitecore-experience-manager/cdn-setup-considerations.html "CDN setup considerations")。

## Sitecoreメディアライブラリを手動で設定してください

Sitecoreメディアライブラリを手動で設定し、CDNを使えるようにします:

1.  Sitecore Content Delivery(CD)サーバーで、*Sitecore deployment*フォルダに行ってください。
    
2.  App\_Config\\Includeでは、*CDN*という名前のフォルダを作成します。
    
3.  *CDN*フォルダ内にファイルを作成し、以下の名前を付けます:CDN.config
    
4.  CDN.configファイルを編集し、以下の情報をファイルに保存してください:
    
    > !注*[http://example.com](http://example.com)*の代わりに、CDNエンドポイントのURLを使いましょう。
    
    <?xml version="1.0" encoding="utf-8"?>
    
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    
        <sitecore>
    
            <settings>
    
                <!-- 
    
    MediaResponse.AlwaysIncludeServerUrl must be true, to always include CDN
    url when getting media item url.
    
                      Otherwise, the request will
    not be served by CDN server.
    
                -->
    
                <setting name="Media.AlwaysIncludeServerUrl">
    
                    <patch:attribute name="value">true</patch:attribute>
    
                </setting>
    
                <!-- 
    
    MediaResponse.MediaLinkServerUrl must be set to url of the CDN endpoint.
    
                      Change it from http://example.com, to the url of the CDN
    endpoint.
    
                -->
    
                <setting name="Media.MediaLinkServerUrl">
    
                    <patch:attribute name="value">http://example.com</patch:attribute>
    
                </setting>
    
                <!-- 
    
    MediaResponse.AlwaysAppendRevision should be true to always append
    revision when getting media item url.
    
                      The purpose of the value is
    to generate a unique URL for every revision.
    
                -->           
    
                <setting name="Media.AlwaysAppendRevision">
    
                    <patch:attribute name="value">true</patch:attribute>
    
                </setting>
    
                <!-- 
    
                      MediaResponse.Cacheability
    must be Public to let the CDN server cache the response.
    
                      Otherwise instead of caching
    the response, the CDN server will ask for the response from Sitecore server
    every time.
    
                -->
    
                <setting name="MediaResponse.Cacheability">
    
                    <patch:attribute name="value">Public</patch:attribute>
    
                </setting>
    
                <!-- 
    
                     The max-age to use in media
    response headers.
    
                     CDN server uses this value as
    max-age of the response cache.
    
                -->
    
                <setting name="MediaResponse.MaxAge">
    
                    <patch:attribute name="value">7.\`00:00\`:00</patch:attribute>
    
                </setting>
    
            </settings>
    
        </sitecore>
    
    </configuration>
    
    > !注この例の設定ファイルは、ルート*Sitecore*フォルダのApp\_Config\\Include\\Examples\\CDN.config.example.も見つけられます。
    
    設定値の詳細については、[Sitecore Media Library CDN関連の設定リファレン](https://doc.sitecore.com/xp/ja/developers/103/sitecore-experience-manager/sitecore-media-library-cdn-related-configuration-reference.html "Sitecore Media Library CDN-related configuration reference")スを参照してください。
    
5.  [SitecoreメディアライブラリCDNサポートの開発者考慮](https://doc.sitecore.com/xp/ja/developers/103/sitecore-experience-manager/developer-considerations-for-the-sitecore-media-library-cdn-support.html "Developer considerations for the Sitecore Media Library CDN support")事項(*「CDN対応メディアアイテムURLを取得する*こと)」セクションで記載されたオプションのいずれかを使って作成されたURLには、CDNのURLとリビジョン番号が含まれていることを確認してください。