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?

Rocky Linux 9で稼働するDockerコンテナのDNS設定

Posted at

Rocky Linux 9上にWebアプリケーションをDockerコンテナとしてビルドした際に、
独自ドメインを設定する方法。

DNSをサーバーに向ける

ドメインを取得したサイト(お名前.com 等)で、Aレコードを設定。

www.example.com(設定したい独自の完全修飾ドメイン) → 000.000.00.00(サーバーのIPアドレス)
example.com → 000.000.00.00

TTL は 300 〜 3600 ぐらいで設定。

Rocky Linux に Nginx をインストール

sudo dnf install -y nginx
sudo systemctl enable --now nginx

http://サーバーIP で nginx のデフォルトページが見える。

Nginx から Docker コンテナへプロキシ

デプロイするWebアプリケーション用に、nginxの設定ファイルを作成。

sudo vi /etc/nginx/conf.d/example.conf

コンテナが localhost の 8080 で動いている前提で、以下の内容を記述。

example.conf
server {
    listen 80;
    server_name example.com www.example.com;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

設定ファイルをテスト。

sudo nginx -t

nginxを再起動

sudo systemctl restart nginx

ブラウザでhttp://www.example.com
にアクセスして、サイトが表示されればOK。

Let's Encrypt(certbot)でSSL化

certbotをインストール

sudo dnf install -y certbot python3-certbot-nginx
  • SSL 証明書発行
  • nginx 設定の自動編集
  • https リダイレクト追加
  • 自動更新 cron 設定

を以下のコマンドでよしなにやってくれる。

sudo certbot --nginx -d example.com -d www.example.com

これで、https://www.example.com
にアクセスして、サイトが表示されればOK。

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?