0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ECSでWordPress構築

Posted at

はじめに

ECSでWordPressを立ち上げてみました。前提環境(VPC、ALB、RDS等)はTerraformにて過去記事で作成しているので本記事ではコンソール上でのFargate構築にフォーカスします。

構成

構成図.png

Dockefileの作成

FROM wordpress:6.7.2-php8.1-apache

RUN set -ex; \
    apt-get update && apt-get install -y \
        wget \
        unzip \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# プラグイン関連の作業ディレクトリ変更
WORKDIR /usr/src/wordpress/wp-content/plugins

RUN set -ex; \
    wget -q -O amazon-s3-and-cloudfront.zip https://downloads.wordpress.org/plugin/amazon-s3-and-cloudfront.3.2.11.zip \
    && unzip -q -o '*.zip' -d /usr/src/wordpress/wp-content/plugins \
    && chown -R www-data:www-data /usr/src/wordpress/wp-content/plugins \
    && rm -f '*.zip'

RUN chown -R www-data:www-data /var/www/html

# 作業ディレクトリをデフォルトに変更
WORKDIR /var/www/html

ECRにプッシュ

$ docker push hogehoge.dkr.ecr.ap-northeast-1.amazonaws.com/wordpress:latest
The push refers to repository [hogehoge.dkr.ecr.ap-northeast-1.amazonaws.com/wordpress]
latest: digest: sha256:ebf95d66d646e28adfdf395bfa7cbbcc4b9f4cce803050370e5b12 size: 856

ECS

クラスタの作成

202503027_000004.JPG

タスク定義の作成

202503027_000001.JPG

202503027_000002.JPG

DBへの接続確立のために追加します。値のタイプをValueformにするとSSMパラメータを参照してしまうので注意。

202503027_000012.JPG

サービスの作成

  • ↓に加えてネットワーキング設定で上の構成でのVPC、パブリックサブネットとSG、ロードバランシング設定では既存のLB、TG、Listnerを使用する。
    202503027_000005.JPG

確認

ヘルスチェック

  • ターゲットタイプがIPかつ上で作成したタスクのプライベートIPがターゲットとして登録されている
    202503027_000010.JPG

リクエスト

項目 説明
HTTPステータスコード HTTP/1.1 302 Found リダイレクトの発生を示す
Location リダイレクト先URL 独自ドメインにリダイレクトされている
Server MWとOSがドッカーイメージのものと一致 (Apache/2.4.62 (Debian))
X-Powered-By PHP (PHP/8.1.32)
X-Redirect-By WordPressがリダイレクトを行っている
Cache-Control キャッシュ設定がCaching Disabled(オリジンから)

202503027_000015.JPG

WordPress

202503027_000011.JPG

最後に

次回は今回コンソールで作成したパラメータから、TerraformでECRリポジトリ、ECSクラスタ、タスク定義、サービスを作成するテンプレートを作成してみる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?