2025年12月19日金曜日

リバース・プロキシとして構成したnginxでWWW-Authenticateヘッダーを書き換える

Oracle REST Data Servicesに実装したリモートMCPサーバーをOAuth2で保護するにあたって、401エラーとともに返されるWWW-Authenticateヘッダーにresource_metadataやscopeを含める方法を調べてみました。

nginxにmore_clear_headersのモジュールを組み込みエラー・ページを置き換えることにより、WWW-Authenticateヘッダーを置き換えることができました。

このモジュールの組み込みを簡単に行うために、UbuntuにOracle APEX環境を作りました。

Ubuntu 24.04では以下のコマンドを実行して、nginxのmore_clear_headersを含むモジュールをインストールします。

apt install libnginx-mod-http-headers-more-filter

Oracle Linux 10でもEPELリポジトリ(ol10_u0_developer_EPEL)にnginx-mod-headers-moreとして含まれていました。以下のコマンドを実行して、more_clear_headersを含むnginxのモジュールをインストールします。

dnf -y install nginx-mod-headers-more

ORDSの/ords/apexdev/sampleserver/mcpが401を返すときに、WWW-Authenticateヘッダーを置き換える設定は以下になります。ヘッダーにresource_metadataを含めています。

Postmanで動作を確認しました。

proxy_intercept_errorsを無効にしていると、WWW-Authenticateヘッダーには以下の値が返されます。

Bearer realm="Oracle REST Data Services", error="invalid_token"


proxy_intercept_errorsを有効にすると、WWW-Authenticateヘッダーには以下の値が返されます。

Bearer resource_metadata="https://ホスト名/.well-known/oauth-protected-resource/ords/apexdev/sampleserver/mcp"


ここにscopeを入れることで、Microsoft Entra IDで保護しているリモートMCPサーバーでも、ChatGPTやClaude Desktopからアクセスできるようにできると思ったのですが、それだけでは無かったです。

とはいえ、WWW-Authenticateヘッダーを調整することにより、リソース・サーバーとしての設定を色々と変えられるようになりました。

今回の記事は以上です。

Ubuntu 24.04にOracle APEXの環境を作成する

Oracle CloudでUbuntu 24.04のComputeインスタンスを作成し、その上でOracle APEXの環境を構築してみました。Oracle APEXの実行に必要なOracle DatabaseおよびOracle REST Data Servicesともにコンテナ・イメージを使用するため、オペレーティング・システムやJavaの依存性を意識せずにAPEX環境を構築できます。

以前の記事「ORDSのRESTサービスとして作成したリモートMCPサーバーをMicrosoft Entra IDで認証する」にそって、作業を実施します。オペレーティング・システムの違いが環境構築手順のどこに影響するか不明だったため、差分ではなく一通りの手順を記録します。

以下より、Ubuntu 24.04でのOracle APEXの環境構築手順を紹介します。

Ubuntu 24.04のインスタンスに接続します。rootユーザーの作業が続くので、最初にrootに切り替えます。

sudo -s

ubuntu@ubapex:~$ sudo -s

root@ubapex:/home/ubuntu# 


podman、nginxおよびunzipをインストールします。

apt install -y podman nginx unzip

root@ubapex:/home/ubuntu# apt install -y podman nginx unzip

Reading package lists... Done

Building dependency tree... Done

Reading state information... Done

The following additional packages will be installed:

  aardvark-dns buildah catatonit conmon containernetworking-plugins crun

  fuse-overlayfs golang-github-containers-common

  golang-github-containers-image libslirp0 libsubid4 libyajl2 netavark

  nginx-common passt slirp4netns uidmap

Suggested packages:

  containers-storage libwasmedge0 fcgiwrap nginx-doc ssl-cert docker-compose

  zip

The following NEW packages will be installed:

  aardvark-dns buildah catatonit conmon containernetworking-plugins crun

  fuse-overlayfs golang-github-containers-common

  golang-github-containers-image libslirp0 libsubid4 libyajl2 netavark nginx

  nginx-common passt podman slirp4netns uidmap unzip

0 upgraded, 20 newly installed, 0 to remove and 64 not upgraded.

Need to get 33.2 MB of archives.

After this operation, 133 MB of additional disk space will be used.

Get:1 http://iad-ad-3.clouds.archive.ubuntu.com/ubuntu noble/universe amd64 netavark amd64 1.4.0-4 [1666 kB]

Get:2 http://iad-ad-3.clouds.archive.ubuntu.com/ubuntu noble/universe amd64 aardvark-dns amd64 1.4.0-5 [881 kB]


[中略]


Setting up buildah (1.33.7+ds1-1ubuntu0.24.04.3) ...

Processing triggers for man-db (2.12.0-4build2) ...

Processing triggers for libc-bin (2.39-0ubuntu8.6) ...

Scanning processes...                                                           

Scanning linux images...                                                        


Running kernel seems to be up-to-date.


No services need to be restarted.


No containers need to be restarted.


No user sessions are running outdated binaries.


No VM guests are running outdated hypervisor (qemu) binaries on this host.

root@ubapex:/home/ubuntu# 


certbotをインストールします。

snap install --classic certbot

root@ubapex:/home/ubuntu# snap install --classic certbot

certbot 5.2.2 from Certbot Project (certbot-eff) installed

root@ubapex:/home/ubuntu# 


ユーザーoracle、グループoinstallを作成します。

Oracle Databaseなどはコンテナ内でユーザーoracleとして実行されます。コンテナ内からホストのファイル・システムを参照するにあたって、参照するホスト側にあるディレクトリの所有者のUIDやGIDが、コンテナ内のユーザーoracleと一致するようにします。

groupadd -g 54321 oinstall
useradd -u 54321 -g 54321 -m oracle

root@ubapex:/home/ubuntu# groupadd -g 54321 oinstall

root@ubapex:/home/ubuntu# useradd -u 54321 -g 54321 -m oracle

root@ubapex:/home/ubuntu# 


ユーザーoracleがログインしていなくてもサービスが実行できるように、以下のコマンドを実行します。

loginctl enable-linger 54321

root@ubapex:/home/ubuntu# loginctl enable-linger 54321

root@ubapex:/home/ubuntu# 


オペレーティングシステムの設定は以上で完了です。


DB、APEXおよびORDSの構成



Oracle AI Database、Oracle APEXおよびOracle REST Data Servicesを構成します。作業は先ほど作成したユーザーoracleで実施します。インスタンスの接続直後であれば以下のコマンドを実行し、ユーザーoracleに切り替えます。rootから切り替える場合は、sudoは不要です。

sudo su - oracle

ubuntu@ubapex:~$ sudo su - oracle

$ 


Oracle AI Database 26ai Freeのコンテナ・イメージをダウンロードします。

podman pull container-registry.oracle.com/database/free:latest

$ podman pull container-registry.oracle.com/database/free:latest

Trying to pull container-registry.oracle.com/database/free:latest...

Getting image source signatures

Copying blob 97fd3103f315 done   | 

Copying blob 359a083bb2a1 [=>--------------------] 180.6MiB / 1.7GiB | 1.2 MiB/s

Copying blob 97fd3103f315 done   | 

Copying blob 359a083bb2a1 done   | 

Copying blob 5bf4d5bb53fa done   | 

Copying blob a788b7aca3f6 done   | 

Copying blob d564e67f1ed2 done   | 

Copying blob 867532f50b57 done   | 

Copying blob 3852ff38ea46 done   | 

Copying blob 325b6722024f done   | 

Copying blob d1e8ff124bb5 done   | 

Copying blob f3f45addaa5c done   | 

Copying blob 21f5b3d4bded done   | 

Copying blob c62f5145519a done   | 

Copying blob 1ae8998597b3 done   | 

Copying blob c4dd45b650b9 done   | 

Copying blob 42048da13555 done   | 

Copying blob 61135ed510cd done   | 

Copying blob e774aa72c2b3 done   | 

Copying blob 73e204b18f80 done   | 

Copying blob 2a2ff731d809 done   | 

Copying blob 0361c3d5b31e done   | 

Copying blob 78d585384f78 done   | 

Copying blob 8b75f497490b done   | 

Copying config 3c986e106c done   | 

Writing manifest to image destination

3c986e106c3e8ae13457ccd8b6638417ddfae7bcf73f75a0d4291ae14bd46116

$ 


Oracle REST Data Servicesのコンテナ・イメージをダウンロードします。

podman pull container-registry.oracle.com/database/ords:latest

$ podman pull container-registry.oracle.com/database/ords:latest

Trying to pull container-registry.oracle.com/database/ords:latest...

Getting image source signatures

Copying blob d81d5a90619a done   | 

Copying blob 6b7be68c6d11 done   | 

Copying blob dfff58bca405 done   | 

Copying blob ac06ceafe5b9 done   | 

Copying blob fe5b07d1ad75 done   | 

Copying blob 1a368acc7480 done   | 

Copying blob ee5944a79ed7 done   | 

Copying blob 4f4fb700ef54 done   | 

Copying config fee0124fd9 done   | 

Writing manifest to image destination

fee0124fd9a388de0c0819b3d42e1941d9b1b36942dc2cf68ac6767cca2205d4

$ 


Oracle APEXの最新版のアーカイブをダウンロードし、/home/oracle以下に展開します。

curl -O https://download.oracle.com/otn_software/apex/apex-latest.zip
unzip -q apex-latest.zip
ls apex

$ curl -O https://download.oracle.com/otn_software/apex/apex-latest.zip

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100  289M  100  289M    0     0   138M      0  0:00:02  0:00:02 --:--:--  138M

$ unzip -q apex-latest.zip

$ ls apex

LICENSE.txt     apxdevrm_cdb.sql apxrtins_cdb.sql

apex_rest_config.sql     apxdevrm_nocdb.sql apxrtins_nocdb.sql

apex_rest_config_cdb.sql    apxdvins.sql apxsilentins.sql

apex_rest_config_core.sql   apxdvins_cdb.sql builder

apex_rest_config_nocdb.sql  apxdvins_nocdb.sql core

apexins.sql     apxdwngrd.sql coreins.sql

apexins1.sql     apxpatch.sql coreins2.sql

apexins2.sql     apxpatch_cdb.sql coreins3.sql

apexins3.sql     apxpatch_nocdb.sql coreins4.sql

apexins_adb.sql     apxremov.sql coreins5.sql

apexins_adb_ext.sql     apxremov1.sql dbcsconf.sql

apexins_cdb.sql     apxremov2.sql dbcsins.sql

apexins_nocdb.sql     apxremov_cdb.sql devins.sql

appins.sql     apxremov_nocdb.sql images

apxappcon.sql     apxrtins.sql load_trans.sql

apxappcon_ext.sql     apxrtins1.sql utilities

apxchpwd.sql     apxrtins2.sql

apxdevrm.sql     apxrtins3.sql

$ 


データ・ファイルを配置するディレクトリを/home/oracle/oradataとして作成します。その後、データベースのコンテナの作成と実行を行います。コンテナを作成するpodman runコマンドが完了するまで、少々時間がかかります。

構成が完了するまでログを確認します。

mkdir oradata
podman run -d --name apex-db --privileged --userns=keep-id:uid=54321,gid=54321 -p 1521:1521 -v /home/oracle/oradata:/opt/oracle/oradata -v /home/oracle/apex:/home/oracle/apex container-registry.oracle.com/database/free:latest
podman logs -f apex-db


$ mkdir oradata

$ podman run -d --name apex-db --privileged --userns=keep-id:uid=54321,gid=54321 -p 1521:1521 -v /home/oracle/oradata:/opt/oracle/oradata -v /home/oracle/apex:/home/oracle/apex container-registry.oracle.com/database/free:latest

e8e872459fd6588bce0d013edadef1a30b8f15ded0a6b062e34ce1e13dc0d9e9

$ podman logs -f apex-db

Specify a password to be used for database accounts. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9]. Note that the same password will be used for SYS, SYSTEM and PDBADMIN accounts:

Confirm the password:

Configuring Oracle Listener.

Listener configuration succeeded.

Configuring Oracle AI Database FREE.

Enter SYS user password: 

****************

Enter SYSTEM user password: 

***************

Enter PDBADMIN User Password: 

***************

Prepare for db operation

7% complete

Copying database files

29% complete

Creating and starting Oracle instance

30% complete

33% complete

36% complete

39% complete

43% complete

Completing Database Creation

47% complete

49% complete

50% complete

Creating Pluggable Databases

54% complete

71% complete

Executing Post Configuration Actions

93% complete

Running Custom Scripts

100% complete

Database creation complete. For details check the logfiles at:

 /opt/oracle/cfgtoollogs/dbca/FREE.

Database Information:

Global Database Name:FREE

System Identifier(SID):FREE

Look at the log file "/opt/oracle/cfgtoollogs/dbca/FREE/FREE.log" for further details.


Connect to Oracle AI Database using one of the connect strings:

     Pluggable database: e8e872459fd6/FREEPDB1

     Multitenant container database: e8e872459fd6


SQL*Plus: Release 23.26.0.0.0 - Production on Fri Dec 19 02:15:41 2025

Version 23.26.0.0.0


Copyright (c) 1982, 2025, Oracle.  All rights reserved.



Connected to:

Oracle AI Database 26ai Free Release 23.26.0.0.0 - Develop, Learn, and Run for Free

Version 23.26.0.0.0


SQL> 

System altered.


SQL> 

Pluggable database altered.


SQL> 

PL/SQL procedure successfully completed.


SQL> SQL> 

Session altered.


SQL> 

User created.


SQL> 

Grant succeeded.


SQL> 

Grant succeeded.


SQL> 

Grant succeeded.


SQL> 

User altered.


SQL> SQL> Disconnected from Oracle AI Database 26ai Free Release 23.26.0.0.0 - Develop, Learn, and Run for Free

Version 23.26.0.0.0


SQL*Plus: Release 23.26.0.0.0 - Production on Fri Dec 19 02:15:41 2025

Version 23.26.0.0.0


Copyright (c) 1982, 2025, Oracle.  All rights reserved.



Connected to:

Oracle AI Database 26ai Free Release 23.26.0.0.0 - Develop, Learn, and Run for Free

Version 23.26.0.0.0


SQL> Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> ORACLE instance started.


Total System Global Area 1603373280 bytes

Fixed Size     5007584 bytes

Variable Size   402653184 bytes

Database Buffers 1191182336 bytes

Redo Buffers     4530176 bytes

Database mounted.

SQL> 

Database altered.


SQL> 

Database altered.


SQL> 

Database altered.


SQL> SQL> Disconnected from Oracle AI Database 26ai Free Release 23.26.0.0.0 - Develop, Learn, and Run for Free

Version 23.26.0.0.0

The Oracle base remains unchanged with value /opt/oracle


Executing user defined scripts

/opt/oracle/runUserScripts.sh: running /opt/oracle/scripts/extensions/setup/registerService.sh


DONE: Executing user defined scripts


The Oracle base remains unchanged with value /opt/oracle

#########################

DATABASE IS READY TO USE!

#########################

The following output is now a tail of the alert.log:

2025-12-19T02:15:50.984853+00:00

PDB$SEED(2):Opening pdb with Resource Manager plan: DEFAULT_PLAN

(3):--ATTENTION--

(3):PARALLEL_MAX_SERVERS (with value 1) is insufficient. This may affect transaction recovery performance.

Modify PARALLEL_MAX_SERVERS parameter to a value > 4 (= parallel servers count computed from parameter FAST_START_PARALLEL_ROLLBACK) in PDB ID 3

FREEPDB1(3):Autotune of undo retention is turned on. 

2025-12-19T02:15:51.405062+00:00

FREEPDB1(3):Opening pdb with Resource Manager plan: DEFAULT_PLAN

Completed: Pluggable database FREEPDB1 opened read write 

Completed: ALTER DATABASE OPEN

2025-12-19T02:15:52.235049+00:00

===========================================================

Dumping current patch information

===========================================================

No patches have been applied

===========================================================

2025-12-19T02:15:52.411915+00:00

FREEPDB1(3):Resize operation completed for file# 13, fname /opt/oracle/oradata/FREE/FREEPDB1/sysaux01.dbf, old size 409600K, new size 430080K

^C$ 


データベースのSYSのパスワードを環境変数ORACLE_PWDに設定します。[パスワード]の部分に、パスワードとして適切な文字列を指定します。今後の作業で複数回、SYSのパスワードを指定する箇所があるため、打ち間違いなどを防止します。

その上で、作成したデータベースのSYSのパスワードを変更します。

export ORACLE_PWD=[パスワード]
podman exec -it apex-db sh setPassword.sh $ORACLE_PWD

$ export ORACLE_PWD=********

$ podman exec -it apex-db sh setPassword.sh $ORACLE_PWD

The Oracle base remains unchanged with value /opt/oracle


SQL*Plus: Release 23.26.0.0.0 - Production on Fri Dec 19 02:19:59 2025

Version 23.26.0.0.0


Copyright (c) 1982, 2025, Oracle.  All rights reserved.



Connected to:

Oracle AI Database 26ai Free Release 23.26.0.0.0 - Develop, Learn, and Run for Free

Version 23.26.0.0.0


SQL> 

User altered.


SQL> 

User altered.


SQL> 

Session altered.


SQL> 

User altered.


SQL> Disconnected from Oracle AI Database 26ai Free Release 23.26.0.0.0 - Develop, Learn, and Run for Free

Version 23.26.0.0.0

$ 


コンテナapex-dbに接続し、データベースにAPEXをインストールします。

podman exec -it apex-db bash

$ podman exec -it apex-db bash

bash-4.4$ 


APEXのイメージが展開されたディレクトリ/home/oracle/apexへ移動し、データベースに接続してAPEXのインストールを実行します。

cd apex
export NLS_LANG=American_America.AL32UTF8
sqlplus / as sysdba
alter session set container = freepdb1;
@apexins SYSAUX SYSAUX TEMP /i/

bash-4.4$ cd apex

bash-4.4$ export NLS_LANG=American_America.AL32UTF8

bash-4.4$ sqlplus / as sysdba


SQL*Plus: Release 23.26.0.0.0 - Production on Fri Dec 19 02:22:15 2025

Version 23.26.0.0.0


Copyright (c) 1982, 2025, Oracle.  All rights reserved.



Connected to:

Oracle AI Database 26ai Free Release 23.26.0.0.0 - Develop, Learn, and Run for Free

Version 23.26.0.0.0


SQL> alter session set container = freepdb1;


Session altered.


SQL> @apexins SYSAUX SYSAUX TEMP /i/

...set_appun.sql


PL/SQL procedure successfully completed.














...set_ufrom_and_upgrade.sql


PL/SQL procedure successfully completed.



[中略]


Thank you for installing Oracle APEX 24.2.0


Oracle APEX is installed in the APEX_240200 schema.


The structure of the link to the Oracle APEX Administration Services is as follows:

http://host:port/ords/apex_admin


The structure of the link to the Oracle APEX development environment is as follows:

http://host:port/ords/apex



timing for: Phase 3 (Switch)

Elapsed:    0.15



timing for: Complete Installation

Elapsed:    3.62


SYS> 


APEXのインストールが完了したのち、続けて日本語リソースをロードします。

@load_trans JAPANESE

SYS> @load_trans JAPANESE


PL/SQL procedure successfully completed.


Installing Oracle APEX translation - JAPANESE


. ORACLE

.

. Oracle APEX Hosted Development Service Installation.

..............................................................


PL/SQL procedure successfully completed.


[中略]


--application/pages/page_00206

--application/deployment/definition

--application/deployment/checks

--application/deployment/buildoptions

--application/end_environment

... elapsed: 2.95 sec

...done

Adjust instance settings


PL/SQL procedure successfully completed.


SYS> 


データベース・ユーザーAPEX_PUBLIC_USERをアンロックします。

alter user apex_public_user account unlock no authentication;

SYS> alter user apex_public_user account unlock no authentication;


User altered.


SYS> 


管理者ユーザーとパスワードを設定します。管理者ユーザー名はデフォルトのADMINとします。

@apxchpwd

SYS> @apxchpwd

...set_appun.sql

================================================================================

This script can be used to change the password of an Oracle APEX

instance administrator. If the user does not yet exist, a user record will be

created.

================================================================================

Enter the administrator's username [ADMIN] 

User "ADMIN" does not yet exist and will be created.

Enter ADMIN's email [ADMIN] 

Enter ADMIN's password [] **********

Created instance administrator ADMIN.


SYS> 


sqlplusを終了します。続けて、コンテナapex-dbから抜け、ホストに戻ります。

exit
exit


SYS> exit

Disconnected from Oracle AI Database 26ai Free Release 23.26.0.0.0 - Develop, Learn, and Run for Free

Version 23.26.0.0.0

bash-4.4$ exit

exit

$ 


Oracle REST Data Servicesのコンテナの作成と実行を行います。構成情報を保存するディレクトリとして/home/oracle/ords_configを作成し、コンテナ内の/etc/ords/configにマウントします。

接続先のデータベースはコンテナの外にあるため、DBHOSTはlocalhostではなく、host.containers.internalを指定します。

mkdir ords_config
podman run -d --name apex-ords --privileged --userns=keep-id:uid=54321,gid=54321 -e DBHOST=host.containers.internal -e DBPORT=1521 -e DBSERVICENAME=freepdb1 -e ORACLE_PWD=$ORACLE_PWD -p 8080:8080 -v /home/oracle/ords_config:/etc/ords/config -v /home/oracle/apex:/opt/oracle/apex container-registry.oracle.com/database/ords:latest
podman logs -f apex-ords


ORDSが正常に起動されたらログの確認を停止し、次の作業へ移ります。

$ mkdir ords_config

$ podman run -d --name apex-ords --privileged --userns=keep-id:uid=54321,gid=54321 -e DBHOST=host.containers.internal -e DBPORT=1521 -e DBSERVICENAME=freepdb1 -e ORACLE_PWD=$ORACLE_PWD -p 8080:8080 -v /home/oracle/ords_config:/etc/ords/config -v /home/oracle/apex:/opt/oracle/apex container-registry.oracle.com/database/ords:latest

4092fd95bafc484c69adfc1e4d11c7255d7b8536587bd3ee1bcca56987cfd8df

$ podman logs -f apex-ords

Testing database connection...

INFO : Attempt 1: Connecting to sys/*****@host.containers.internal:1521/freepdb1 as sysdba...

INFO : Database connection successful.

INFO : The Oracle REST Data Services are not installed on your database.

INFO : Installing The Oracle REST Data Services 25.4.0.

INFO : The ORACLE_USER_PWD variable was not supplied.

       A temporary password was generated for ORACLE_USER_PWD.

       Execute this command to get the generated password:

       docker exec <ORDS_container_name> ords config get --secret db.password

INFO : The Oracle REST Data Services 25.4.0 has been installed correctly on your database.


[中略]


2025-12-19T02:38:01.067Z INFO        Created Pool: |default|lo|-2025-12-19T02-38-00.445036067Z at: 2025-12-19T02:38:00.445036067Z

2025-12-19T02:38:01.148Z INFO        


Mapped local pools from /etc/ords/config/databases:

  /ords/                              => default                        => VALID     



2025-12-19T02:38:01.158Z INFO        Oracle REST Data Services initialized

Oracle REST Data Services version : 25.4.0.r3441128

Oracle REST Data Services server info: jetty/12.0.25

Oracle REST Data Services java info: Java HotSpot(TM) 64-Bit Server VM GraalVM EE 21.3.10 (build 17.0.11+7-LTS-jvmci-21.3-b51 mixed mode, sharing)


2025-12-19T02:38:01.239Z INFO        CursorMonitor 1

2025-12-19T02:38:01.240Z INFO        RequestMonitor 1

2025-12-19T02:38:01.240Z INFO        TransactionMonitor 1

2025-12-19T02:38:01.241Z INFO        AccessLogMonitor 1 0

2025-12-19T02:38:01.242Z INFO        WatchdogMonitor 1


以上でAPEXおよびORDSにアクセスできるようになりました。ただし、ORDSはポート8080で接続を待ち受けているため、この時点でAPEXへの接続を確認するには、ポート8080への接続を許可するファイアウォールルールを作成する必要があります。


nginxによるリバース・プロキシの構成



nginxによるリバース・プロキシを構成します。nginxにてHTTPS接続を受け付け、バックエンドのORDSとは、httpで通信します。

nginxはコンテナではなくホストで実行します。作業はrootユーザーにて実施します。

sudo -s

ubuntu@ubapex:~$ sudo -s

root@ubapex:/home/ubuntu# 


Oracle CloudのComputeインスタンスでUbuntu 24.04を選択したときに限定された構成だと思いますが、iptables(実際にはnft)により、デフォルトではsshによる接続のみが許可されています。

iptables -L INPUT -n --line-numbers

root@ubapex:/home/ubuntu# iptables -L INPUT -n --line-numbers

Chain INPUT (policy ACCEPT)

num  target     prot opt source               destination         

1    ACCEPT     0    --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED

2    ACCEPT     1    --  0.0.0.0/0            0.0.0.0/0           

3    ACCEPT     0    --  0.0.0.0/0            0.0.0.0/0           

4    ACCEPT     6    --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22

5    REJECT     0    --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

root@ubapex:/home/ubuntu# 


http(80)およびhttps(443)を宛先とした接続を許可します。

iptables -I INPUT 5 -p tcp --dport 80 -m conntrack --ctstate NEW -j ACCEPT
iptables -I INPUT 6 -p tcp --dport 443 -m conntrack --ctstate NEW -j ACCEPT
iptables -L INPUT -n --line-numbers

root@ubapex:/home/ubuntu# iptables -I INPUT 5 -p tcp --dport 80 -m conntrack --ctstate NEW -j ACCEPT

root@ubapex:/home/ubuntu# iptables -I INPUT 6 -p tcp --dport 443 -m conntrack --ctstate NEW -j ACCEPT

root@ubapex:/home/ubuntu# iptables -L INPUT -n --line-numbers

Chain INPUT (policy ACCEPT)

num  target     prot opt source               destination         

1    ACCEPT     0    --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED

2    ACCEPT     1    --  0.0.0.0/0            0.0.0.0/0           

3    ACCEPT     0    --  0.0.0.0/0            0.0.0.0/0           

4    ACCEPT     6    --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22

5    ACCEPT     6    --  0.0.0.0/0            0.0.0.0/0            tcp dpt:80 ctstate NEW

6    ACCEPT     6    --  0.0.0.0/0            0.0.0.0/0            tcp dpt:443 ctstate NEW

7    REJECT     0    --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

root@ubapex:/home/ubuntu# 


設定を永続化します。

netfilter-persistent save
netfilter-persistent reload

root@ubapex:/home/ubuntu# netfilter-persistent save

run-parts: executing /usr/share/netfilter-persistent/plugins.d/15-ip4tables save

run-parts: executing /usr/share/netfilter-persistent/plugins.d/25-ip6tables save

root@ubapex:/home/ubuntu# netfilter-persistent reload

run-parts: executing /usr/share/netfilter-persistent/plugins.d/15-ip4tables start

run-parts: executing /usr/share/netfilter-persistent/plugins.d/25-ip6tables start

root@ubapex:/home/ubuntu# 


外部からの接続を確認するにあたって、デフォルトの設定でnginxを起動します。

systemctl start nginx

root@ubapex:/home/ubuntu# systemctl start nginx

root@ubapex:/home/ubuntu# 


curtlコマンドなどを使用して、外部からHTTPでの接続確認ができれば接続許可の設定は完了です。

certbotを実行し、Let's Encryptより証明書を取得します。デフォルトでは楕円曲線暗号の鍵を生成するようです。ORDSでの利用を考えている場合は--key-type rsaをオプションとして追加し、RSAの鍵を生成します。

ポート80を解放するため、実行中のnginxを停止します。

systemctl stop nginx

root@ubapex:/home/ubuntu# systemctl stop nginx

root@ubapex:/home/ubuntu# 


以下の例ではホスト名にordsmcp.f5.siを指定していますが、作業の際には割り当てているホスト名に置き換えます。

certbot certonly --standalone -d ordsmcp.f5.si

root@ubapex:/home/ubuntu# certbot certonly --standalone -d ordsmcp.f5.si

Saving debug log to /var/log/letsencrypt/letsencrypt.log

Enter email address or hit Enter to skip.

 (Enter 'c' to cancel): [申請者のメールアドレス]


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Please read the Terms of Service at:

https://letsencrypt.org/documents/LE-SA-v1.6-August-18-2025.pdf

You must agree in order to register with the ACME server. Do you agree?

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

(Y)es/(N)o: Y


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Would you be willing, once your first certificate is successfully issued, to

share your email address with the Electronic Frontier Foundation, a founding

partner of the Let's Encrypt project and the non-profit organization that

develops Certbot? We'd like to send you email about our work encrypting the web,

EFF news, campaigns, and ways to support digital freedom.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

(Y)es/(N)o: N

Account registered.

Requesting a certificate for ordsmcp.f5.si


Successfully received certificate.

Certificate is saved at: /etc/letsencrypt/live/ordsmcp.f5.si/fullchain.pem

Key is saved at:         /etc/letsencrypt/live/ordsmcp.f5.si/privkey.pem

This certificate expires on 2026-03-19.

These files will be updated when the certificate renews.

Certbot has set up a scheduled task to automatically renew this certificate in the background.


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

If you like Certbot, please consider supporting our work by:

 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate

 * Donating to EFF:                    https://eff.org/donate-le

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

root@ubapex:/home/ubuntu# 


nginx構成ファイルを置き換えます。

/etc/nginx/nginx.confを以下に置き換えます。

デバッグ用途に、ORDSへ送信されるヘッダーやリクエスト本体をログに出力する設定を含めています(有効にはしていません)。

TLSを有効にしたサーバーの設定ファイルを、/etc/nginx/conf.d/01-server.confとして作成します。ホスト名のordsmcp.f5.siの部分は、適切なホスト名に置き換えます。Oracle Linux 10にインストールされるnginxと比較すると若干バージョンが低かったため、いくつか設定を変えています。

ORDSおよびAPEXへのリバース・プロキシの設定、および、OAuth2の認証で使用するファイルを配置する/.well-known/を設定するファイルとして、/etc/nginx/default.d/01-apex.confを作成します。

Ubuntu 24.04のインスタンスでは/etc/nginx/default.dが作成されていなかったため、最初にディレクトリを作成します。

mkdir /etc/nginx/default.d


nginxに関する設定ファイルを配置しました。nginxを起動します。

systemctl enable nginx
systemctl start nginx

root@ubapex:/home/ubuntu# systemctl enable nginx

Synchronizing state of nginx.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.

Executing: /usr/lib/systemd/systemd-sysv-install enable nginx

root@ubapex:/home/ubuntu# systemctl start nginx

root@ubapex:/home/ubuntu# 


nginxではhttpsからhttpへのリバース・プロキシを構成しているため、Oracle REST Data Servicesのsecurity.httpsHeaderCheck"X-Forwarded-Proto: https"を設定します。

ユーザーoracleに切り替えコンテナapex-ordsに接続して、ordsコマンドを実行します。

su - oracle
podman exec -it apex-ords bash
ords --config /etc/ords/config config set security.httpsHeaderCheck "X-Forwarded-Proto: https"

root@ubapex:/home/ubuntu# su - oracle

$ podman exec -it apex-ords bash

[oracle@4092fd95bafc ords]$ ords --config /etc/ords/config config set security.httpsHeaderCheck "X-Forwarded-Proto: https"


ORDS: Release 25.4 Production on Fri Dec 19 04:40:41 2025


Copyright (c) 2010, 2025, Oracle.


Configuration:

  /etc/ords/config


The global setting named: security.httpsHeaderCheck was set to: X-Forwarded-Proto: https

[oracle@4092fd95bafc ords]$ 


コンテナapex-ordsから抜け、再起動して設定を反映します。

exit
podman restart apex-ords


[oracle@4092fd95bafc ords]$ exit

exit

$ podman restart apex-ords

WARN[0010] StopSignal SIGTERM failed to stop container apex-ords in 10 seconds, resorting to SIGKILL 

apex-ords

$ 


以上でAPEXおよびORDSの環境が構築できました。

APEXをインストールしたホストにブラウザより接続します。

https://ホスト名/ords/

Oracle REST Data Servicesのページが開きます。


Oracle APEXを実行すると、APEXワークスペースへのサインインのページが開きます。


これ以降のワークスペースの作成などはオペレーティング・システムの違いの影響を受けないため、作業の紹介は割愛します。

Oracle Databaseのサポート契約があるかたは、APEXの最新パッチをダウンロードできます。


APEX 24.2のパッチはp37366599_2420_Generic.zipとしてダウロードされます。

以下よりパッチの適用手順を紹介します。

パッチは/tmp/p37366599_2420_Generic.zipとして、アップロード済みとします。

ユーザーoracleに切り替えます。

sudo su - oracle

root@ubapex:/home/ubuntu# sudo su - oracle

$ pwd

/home/oracle


パッチをコンテナからアクセスできる/home/oracle/apex以下に解凍します。

unzip -q -d /home/oracle/apex /tmp/p37366599_2420_Generic.zip

パッチは、パッチ番号の名前が付いたディレクトリ/home/oracle/apex/37366599以下に解凍されます。

$ unzip -q -d /home/oracle/apex /tmp/p37366599_2420_Generic.zip

$ ls /home/oracle/apex/37366599

README.txt patch_37859062.sql     wwv_flow_fnd_developer_api.plb

catpatch.sql patch_37859249.sql     wwv_flow_hint.plb

catpatch_appcon.sql patch_37952347.sql     wwv_flow_imp_shared.plb

catpatch_con.sql patch_37967372.sql     wwv_flow_instance_admin.plb

copyu.plb patch_38279730_dev.sql     wwv_flow_ir.plb

corepatch.sql patch_38320934.sql     wwv_flow_mail.plb

devpatch.sql patch_38596648.sql     wwv_flow_maint.plb

f8842.242.sql patch_38669716_dev.sql     wwv_flow_maint_dev.plb

flowc.plb patch_38726720.sql     wwv_flow_native_item.plb

flows_release.sql patch_central_themes.sql     wwv_flow_pdf.plb

flowu.plb provision.plb     wwv_flow_plugin_dev.plb

gen_api_pkg.plb reports3.plb     wwv_flow_print_util.plb

generate_ddl.plb validate_apex.sql     wwv_flow_process_bg.plb

images wwv_dictionary_cache_dev.plb     wwv_flow_pwa.plb

imp_parser.plb wwv_flow_ai.plb     wwv_flow_report_query.plb

meta.plb wwv_flow_ai_dev.plb     wwv_flow_report_query_dev.plb

modules wwv_flow_approval.plb     wwv_flow_security.plb

null1.sql wwv_flow_authentication.plb     wwv_flow_session.plb

patch_36293226_dev.sql wwv_flow_authentication_dev.plb     wwv_flow_session_state.plb

patch_36774907_dev.sql wwv_flow_authentication_native.plb  wwv_flow_sw_parser.plb

patch_37086304.sql wwv_flow_automation.plb     wwv_flow_theme_manager.plb

patch_37155423_dev.sql wwv_flow_branch.plb     wwv_flow_translation_util_api.plb

patch_37355551.sql wwv_flow_builder.plb     wwv_flow_upgrade.plb

patch_37377364.sql wwv_flow_cdn.plb     wwv_flow_web_services_invoker.plb

patch_37403215_dev.sql wwv_flow_copy_page.plb     wwv_flow_web_src_openapi.plb

patch_37473871.sql wwv_flow_data_profile_dev.plb     wwv_flow_web_src_sync.plb

patch_37512460_dev.sql wwv_flow_debug.plb     wwv_flow_wf_management.plb

patch_37553042_dev.sql wwv_flow_doc_src_dev.plb     wwv_flow_workflow.plb

patch_37579661.sql wwv_flow_error.plb     wwv_flow_working_copy_dev.plb

patch_37588311_dev.sql wwv_flow_event_metrics_int.plb     wwv_imp_workspace.plb

patch_37751502.sql wwv_flow_exec_doc_src.plb     wwv_meta_meta_data.plb

patch_37791306.sql wwv_flow_exec_web_src_boss.plb     wwv_sample_dataset.plb

patch_37809911_dev.sql wwv_flow_exec_web_src_http.plb     wwv_util_apex.plb

patch_37830514.sql wwv_flow_f4000_util.plb

patch_37858190.sql wwv_flow_file_editor_dev.plb

$ 


コンテナapex-dbに接続します。

podman exec -it apex-db bash

$ podman exec -it apex-db bash

bash-4.4$ 


パッチを展開したディレクトリに移動します。

cd /home/oracle/apex/37366599
pwd


bash-4.4$ cd /home/oracle/apex/37366599

bash-4.4$ pwd

/home/oracle/apex/37366599

bash-4.4$ 


本パッチで修正された不具合の一覧や、適用手順などはREADME.txtに記載されています。

修正されたイメージファイルを、既存のイメージファイルに上書きコピーします。

cp -rf ./images /home/oracle/apex

bash-4.4$ cp -rf ./images /home/oracle/apex

bash-4.4$ 


catpatch.sqlを実行して、データベース・オブジェクトを修正します。

export NLS_LANG=American_America.AL32UTF8
sqlplus / as sysdba
alter session set container = freepdb1;
@catpatch

bash-4.4$ export NLS_LANG=American_America.AL32UTF8

bash-4.4$ sqlplus / as sysdba


SQL*Plus: Release 23.26.0.0.0 - Production on Fri Dec 19 05:06:21 2025

Version 23.26.0.0.0


Copyright (c) 1982, 2025, Oracle.  All rights reserved.



Connected to:

Oracle AI Database 26ai Free Release 23.26.0.0.0 - Develop, Learn, and Run for Free

Version 23.26.0.0.0


SQL> alter session set container = freepdb1;


Session altered.


SQL> @catpatch


. ORACLE

.

. Oracle APEX 24.2.%

. Patch Set Exception 37366599

........................................


APEX_VERSION

------------------------------

APEX_SCHEMA

--------------------------------------------------------------------------------

24.2.0

APEX_240200




PL/SQL procedure successfully completed.


[中略]


PL/SQL procedure successfully completed.


...Validating APEX

...(05:06:52) Starting validate_apex for APEX_240200

...(05:06:52) Checking missing privileges for APEX_240200

...(05:06:52) Checking missing privileges for APEX_GRANTS_FOR_NEW_USERS_ROLE

...(05:06:52) Re-generating APEX_240200.wwv_flow_db_version

... wwv_flow_db_version is up to date

...(05:06:52) Checking for sys.wwv_flow_cu_constraints

...(05:06:52) Checking invalid public synonyms

...(05:06:52) Key object existence check

...(05:06:53) Post-ORDS updates

...(05:06:53) calling wwv_util_apex_240200.post_ords_upgrade

...enabled_schema

...define_module

...define_template

...define_handler

...set_module_origins_allowed

...(05:06:53) Setting DBMS Registry for APEX to valid

...(05:06:53) Exiting validate_apex


PL/SQL procedure successfully completed.


...Recompiling invalid public synonyms


PL/SQL procedure successfully completed.



PL/SQL procedure successfully completed.


timing for: Complete Patch 37366599

Elapsed: 00:00:19.20

Disconnected from Oracle AI Database 26ai Free Release 23.26.0.0.0 - Develop, Learn, and Run for Free

Version 23.26.0.0.0

bash-4.4$ 


以上でパッチ適用は完了です。

今回の記事は以上になります。

Oracle APEXのアプリケーション作成の参考になれば幸いです。