> For AI agents: the complete documentation index is available at /resource/ucidm/docs/on-premise/1.8.0/llms.txt, the full documentation bundle is available at /resource/ucidm/docs/on-premise/1.8.0/llms-full.txt.

# Reverse Proxy

UCIDM API や管理画面にアクセスするときに HTTPS で通信するためのリバースプロキシを設定します。プロキシサーバーには [Apache](https://httpd.apache.org/) を使います。

あらかじめ、お客様のドメイン向けの SSL/TLS サーバー証明書をご用意ください。

## インストール

```bash
# dnf install -y httpd mod_ssl
```

### SELinux の設定

SELinux が有効な場合はリバースプロキシの振る舞いを許可する必要があります。

SELinux が有効かどうかは次のコマンドで調べられます。

```bash
# getenforce
Enforcing  # SELinux 有効
```

`httpd_can_network_connect` を有効にします。

```bash
# setsebool -P httpd_can_network_connect on
# getsebool httpd_can_network_connect
httpd_can_network_connect --> on
```

SELinux を有効にした状態で通信できないときは `/var/log/audit/audit.log` にログがでていないかをチェックしてください。

### SELinux で許可されているポート番号一覧を調べる

特定のポート番号で通信できないときは許可されているポート番号を試してみてください。

```bash
# dnf install -y policycoreutils-python-utils
# semanage port -l | grep http
```

## apache の設定

```bash
# cd /etc/httpd
# cp -a /opt/osstech/share/ucidm/httpd/* .
```

サンプルの httpd.conf を使ってお客様の環境にあわせた内容に更新します。

### VirtualHost の設定

[VirtualHost ディレクティブ](https://httpd.apache.org/docs/2.4/mod/core.html#virtualhost) でコンテナサービスのポート番号へプロキシする設定を行います。

- ID 連携管理画面やユーザープロファイル画面といった Web UI のプロキシ
- UCIDM API のプロキシ

また [Location ディレクティブ](https://httpd.apache.org/docs/2.4/mod/core.html#location) 単位にアクセス制限の設定を行います。

#### Web UI のプロキシ

```conf
<VirtualHost *:443>
  ServerName serverName.example.com

  <Location "/ui/user">
    ProxyPass http://localhost:5030/ui/user retry=10
    ProxyPassReverse http://localhost:5030/ui/user
    Require all granted
  </Location>

  <Location "/ui/admin">
    ProxyPass http://localhost:5030/ui/admin retry=10
    ProxyPassReverse http://localhost:5030/ui/admin
    Require all granted
  </Location>

  <Location "/ui">
    ProxyPass http://localhost:5030/ui retry=10
    ProxyPassReverse http://localhost:5030/ui
    Require all granted
  </Location>

  <Location "/sys">
    ProxyPass http://localhost:3030/sys retry=10
    ProxyPassReverse http://localhost:3030/sys
    Require all granted
  </Location>

  RewriteEngine On
  RewriteCond %{REQUEST_URI} !^/ui
  RewriteRule ^/$ /ui [R=301,L]
</VirtualHost>
```

#### API サーバーのプロキシ

```conf
<VirtualHost *:8443>
  ServerName serverName.example.com

  <Location "/">
    ProxyPass http://localhost:18080/ retry=10
    ProxyPassReverse http://localhost:18080/
    Require all granted
  </Location>
</VirtualHost>
```

#### SSL/TLS サーバー証明書の設定

動作確認テストのために sample-ca.crt, sample-server.crt, sample.key という自己証明書を使った設定をしています。お客様でご用意いただいた SSL/TLS サーバー証明書を配置してください。

```bash
# ls certs/ private/
certs/:
sample-ca.crt  sample-server.crt
private/:
sample.key
```

VirtualHost ディレクティブで次の設定を変更します。

```
SSLCertificateKeyFile /etc/httpd/private/sample.key
SSLCertificateFile /etc/httpd/certs/sample-server.crt
```

httpd.conf の設定内容が正しいかをチェックします。

```bash
# apachectl configtest
Syntax OK
```

httpd サービスを起動します。

```bash
# systemctl start httpd
```

OS の再起動時に httpd サービスを自動起動するように設定します。

```bash
# systemctl enable httpd
# systemctl is-enabled httpd
enabled
```

## リバースプロキシの疎通確認 \{#local-connection}

httpd の設定完了後、サービスを起動してローカルホストからの HTTPS の疎通確認を行います。

```bash
$ curl --head https://localhost/sys/
HTTP/1.1 200 OK
$ curl --head https://localhost/ui/
HTTP/1.1 200 OK
```

```bash
$ curl https://localhost:8443/status/version
{"serverVersion":"2730fd8","idFederationClientVersion":"ef562e7","mongoDBVersion":"8.0.3","rabbitMQVersion":"4.0.3"}
```

### リモートホストからの疎通確認 \{#remote-connection}

Web ブラウザで `https://${ホスト名}/sys/` へアクセスしてログイン画面が表示されることを確認します。

疎通できない場合はファイアウォールの設定などを確認してください。

```bash
# systemctl status firewalld
```
