---
schema_version: "1"
id: bc9a332ef4233c626d696ffdb6814646f131c06fa5fc64a7d500b230179888c5
title: HTTPS サービスの構築
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/mule-runtime/4.6/build-an-https-service.md
canonical_url: https://docs.mulesoft.com/jp/mule-runtime/4.6/build-an-https-service
source_site: docs.mulesoft.com
content_type: documentation
content_hash: a2c8e7c3211d0890c4859263b17c97fc79739d6493a6c97aafecbcfd143b2cac
description: MuleSoft Documentation Site
release: "4.6"
latest: false
---
# HTTPS サービスの構築

データの機密性を確保するために、HTTPS ベースのサービスを使用して Mule アプリケーションをデプロイできます。次のものを構築する方法を学習します。

- アプリケーションを CloudHub にデプロイする HTTPS サービス
- API Manager プロキシを使用する HTTPS サービス

さらに、HTTP リクエストおよびレスポンスヘッダーの設定方法を学習します。

アプリケーションをローカルにデプロイする場合は、​[「TLS 設定」](https://docs.mulesoft.com/jp/mule-runtime/4.6/tls-configuration)​を参照してください。

## [](#前提条件)前提条件

始める前に、サービス (シンプルな「Hello World」サービスなど) を構築してデプロイします。  
[「API ビルドの最初から最後まで」](https://docs.mulesoft.com/jp/general/api-led-overview)​チュートリアルを使用して、API を設計し、開発する方法を学習します。

## [](#https-サービスの構築)HTTPS サービスの構築

HTTPS を使用してアプリケーションを CloudHub にデプロイするようにサービスを変更します。

1. コマンドラインで JDK ​`keytool`​ ユーティリティを使用して ​`keystore.jks`​ ファイルを作成します。自己署名証明書を生成するには、コマンドラインでホスト名も指定する必要があります。  
    
    たとえば、次のコマンドは、ホスト名に ​`SAN=DNS:localhost,IP:127.0.0.1`​ を指定して ​`keystore.jks`​ ファイルを作成します。
    
    ```text
    keytool -genkeypair -keystore keystore.jks   -dname "CN=localhost, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown"  -keypass password  -storepass password  -keyalg RSA  -sigalg SHA1withRSA  -keysize 2048  -alias mule  -ext SAN=DNS:localhost,IP:127.0.0.1 -validity 9999
    ```
2. 生成された ​`keystore.jks`​ ファイルを Anypoint Studio Mule アプリケーションフォルダーの ​`src/main/resources`​ に追加します。
3. Mule アプリケーションの HTTP リスナーを HTTPS に設定し、次のものを指定します。
    
    - `host`​ の値に HTTPS スキームで使用するホスト IP アドレス。
    - `port`​ の値の ${https.port} 変数の値。

```xml
...
<http:listener-config name="HTTPS_Listener_Configuration" protocol="HTTPS" host="0.0.0.0" port="${https.port}">
     <tls:context>
         <tls:key-store path="keystore.jks" keyPassword="${keystore.password}" password="${password}"/>
     </tls:context>
 </http:listener-config>
...
```

1. HTTPS グローバルリスナー設定への ​`config-ref`​ 参照を含めます。

```xml
<flow name="httpsserviceFlow">
    <http:listener config-ref="HTTPS_Listener_Configuration" path="hello"/>
</flow>
```

1. 外部アドレスへの HTTPS 要求を有効にするために必要な TLS 設定を使用して HTTP リクエスターを設定します。
    
    ```xml
    ...
    <http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="0.0.0.0" port="${https.port}" >
         <tls:context>
             <tls:key-store path="keystore.jks" password="${password}" keyPassword="${keystore.password}" />
         </tls:context>
    </http:request-config>
    ...
    ```

1. HTTPS グローバル要求設定への ​`config-ref`​ 参照を含めます。
    
    ```xml
    <flow name="httpsserviceFlow">
      <http:request config-ref="HTTP_Request_Configuration" path="some-path" method="GET" host="0.0.0.0" port="${https.port}"/>
    </flow>
    ```
    
    これで、アプリケーションを CloudHub にデプロイする準備が整いました。HTTPS アドレス (​`https://yourdomain.cloudhub.io`​ など) を使用してエンドポイントにアクセスできます。

## [](#api-manager-プロキシに基づくサービスの設定)API Manager プロキシに基づくサービスの設定

API Manager からプロキシをダウンロードするように求められており、HTTPS 用に設定する必要がある場合、Anypoint Connector で HTTP 用に HTTP リクエスターを設定したのと同じ手順に従います。この HTTP リスナー設定はテンプレートとして提供されています。

設定を完了する手順は、次のとおりです。

1. プロキシプロジェクトを Anypoint Studio にインポートします。
2. プロキシフローの ​**\[Configuration XML (設定 XML)\]**​ タブを選択します。
    
    フローがコメントアウトされている HTTPS Connector を参照しているため、パーサーでエラーが検出されます。
3. `http:listener-config`​ ブロックのコメントを解除します。
4. `keystore`​ の値を追加します: `path`​、​`password`​、​`keyPassword`​。
    
    ```xml
    <tls:context name="tls-context-config">
        <tls:key-store path="keystore.jks" password="${password}"
           keyPassword="${keystore.password}"/>
    </tls:context>
    ```
    
    - 外部プロパティを使用できます。
    - `path`​ の値に ​`src/main/resources`​ を含めることはできません。
        
        設定は、次のようになります。
        
        ```xml
        <?xml version="1.0" encoding="UTF-8"?>
        
        <mule xmlns:api-platform-gw="http://www.mulesoft.org/schema/mule/api-platform-gw"
        	xmlns:tls="http://www.mulesoft.org/schema/mule/tls" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
        	xmlns:spring="http://www.springframework.org/schema/beans"
        	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        	xsi:schemaLocation="
        http://www.mulesoft.org/schema/mule/api-platform-gw http://www.mulesoft.org/schema/mule/api-platform-gw/current/mule-api-platform-gw.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
        http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
        http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
        http://www.mulesoft.org/schema/mule/tls http://www.mulesoft.org/schema/mule/tls/current/mule-tls.xsd">
              <configuration defaultProcessingStrategy="non-blocking" />
        
            <expression-language:property-placeholder location="config.properties" />
        
            <api-platform-gw:api apiName="![p['api.name']]" version="![p['api.version']]" flowRef="proxy">
            </api-platform-gw:api>
        
            <http:listener-config name="https-lc-0.0.0.0-8082" host="0.0.0.0" port="![p['proxy.port']]" protocol="HTTPS">
                <tls:context name="tls-context-config">
                    <tls:key-store path="keystore.jks" password="${password}"
                                   keyPassword="${keystore.password}"/>
                </tls:context>
             </http:listener-config>
        ...
        ```

## [](#http-リクエストおよびレスポンスヘッダーの設定)HTTP リクエストおよびレスポンスヘッダーの設定

`wrapper.conf`​ ファイルで次のシステムプロパティを変更することで、サーバーレスポンスヘッダー、サーバーリクエストヘッダー、クライアントリクエストヘッダーの最大値を変更できます。

<table class="tableblock frame-all grid-all fit-content spread">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">プロパティ</th>
<th class="tableblock halign-left valign-top">説明</th>
<th class="tableblock halign-left valign-top">デフォルト値</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Server Response Headers (サーバーレスポンスヘッダー)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>mule.http.MAX_SERVER_RESPONSE_HEADERS</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">HTTP サーバーから送信される応答で許容されるヘッダーの最大量。</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>100</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Server Request Headers (サーバーリクエストヘッダー)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>mule.http.MAX_SERVER_REQUEST_HEADERS</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">HTTP サーバーから送信される要求で許容されるヘッダーの最大量。</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>100</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Client Request Headers (クライアントリクエストヘッダー)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>mule.http.MAX_CLIENT_REQUEST_HEADERS</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">HTTP クライアントから送信される要求で許容されるヘッダーの最大量。</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>100</code></p></td>
</tr>
</tbody>
</table>

クライアントの HTTP レスポンスヘッダーには最大量の制限がないため、Max Client Response Header のようなシステムプロパティはありません。

## [](#関連情報)関連情報

- Mule 4 での ​[HTTPS API プロキシの構築](https://docs.mulesoft.com/jp/api-manager/latest/building-https-proxy)
- [HTTP Connector](https://docs.mulesoft.com/jp/http-connector/1.10/)
- [TLS Configuration (TLS 設定)](https://docs.mulesoft.com/jp/mule-runtime/4.6/tls-configuration)