LoginSignup
0
0

More than 1 year has passed since last update.

LightSailでWebサーバを立てる

Last updated at Posted at 2022-02-08

はじめに

備忘として投稿しています。

インスタンス作成

  1. 画面遷移
    Lightsailのホーム画面 > [インスタンス]タブ > [インスタンスの作成]
  2. ロケーション
    東京、ゾーン A (ap-northeast-1a)
  3. プラットフォーム
    Linux/Unix
  4. 設計図
    WordPress スクリーンショット 2022-02-08 22.35.47.png
  5. (オプション)起動スクリプトの作成
    しない
  6. (オプション)SSHキーペアの変更
    [SSHキーペアの変更]をクリックして、デフォルトキーのダウンロードをする。
  7. (オプション)スナップショットの有効化
    スナップショットはWebサーバの作り込み後に設定するので、無効。
    スクリーンショット 2022-02-08 22.37.39.png
  8. インスタンスプランの選択
    ひとまず最安。必要ならいずれスケールアップする。 スクリーンショット 2022-02-08 22.48.38.png
  9. インスタンス名
    任意
  10. (オプション)キーのタグ
    1台のみなので、タグは作成なし。 スクリーンショット 2022-02-08 22.50.55.png
  11. インスタンスの作成をクリック

静的IPアドレスの作成

  1. 画面遷移
    Lightsailのホーム画面 > [ネットワーキング]タブ > [静的IPの作成]
  2. インスタンスへのアタッチ
    作成したインスタンスを選択する。
  3. 静的IPのリソース名
    デフォルト
  4. [作成]をクリック

独自ドメインを取得

FC2の方が安そうだったが、すでに他のドメイン名をお名前.comで取得していたので、お名前.comで取得

DNSゾーンの作成

  1. 画面遷移
    Lightsailのホーム画面 > [ネットワーキング]タブ > [DNSゾーンの作成]
  2. 登録済みドメインの入力
    取得した独自ドメインを入力する。
    スクリーンショット 2022-02-08 23.04.47.png
  3. (オプション)タグの作成
    作成なし。
  4. [DNSゾーンの作成] スクリーンショット 2022-02-08 23.07.27.png

DNSレコードの追加

  1. 画面遷移

    Lightsailのホーム画面 > [ネットワーキング]タブ > 作成したDNSゾーンを選択

  2. [レコードの追加]
    サブドメインは無しでドメインがIPアドレスにポイントするように@を入力する。
    解決先には作成した静的IPを選択する。
    右上のチェックボタンを押す。
    スクリーンショット 2022-02-08 23.21.51.png

  3. ネームサーバを確認(黄色網掛け) してメモっとく。

プロバイダ側でネームサーバを設定

先ほどメモったネームサーバをプロバイダのコンソールで設定。

  1. お名前.comにログイン
  2. ネームサーバの設定をクリック
  3. 独自ドメインにチェック
  4. 先ほどメモったネームサーバを入力
  5. [確認]をクリック
  6. 数分後にはアクセスできた! スクリーンショット 2022-02-08 23.29.35.png スクリーンショット 2022-02-08 23.32.03.png
yoshiki@mbp ~ % nslookup xxxxxxxxxxxxxx.com

Non-authoritative answer:
Name:   xxxxxxxxxxxxxxx.com
Address: xxx.xxx.xxx.xxx

HTTPS化

Bitnami は、bncert-tool という独自の HTTPS 設定ツールを提供しています。
このツールは、以下の手順を自動的に実行します。
・Bitnami スタックで HTTPS 証明書を設定する
・証明書の自動更新を作成する
・HTTP から HTTPS へのリダイレクトをセットアップする

AWS公式 How do I install a standard Let's Encrypt SSL certificate in a Lightsail instance?

1. インスタンスにSSHでログイン

スクリーンショット 2022-02-12 17.34.28.png

2. Bitnamiツールをインストール

Bitnami ドキュメントウェブサイト

wget -O bncert-linux-x64.run https://downloads.bitnami.com/files/bncert/latest/bncert-linux-x64.run
sudo mkdir /opt/bitnami/bncert
sudo mv bncert-linux-x64.run /opt/bitnami/bncert/
sudo chmod +x /opt/bitnami/bncert/bncert-linux-x64.run
sudo ln -s /opt/bitnami/bncert/bncert-linux-x64.run /opt/bitnami/bncert-tool

3. BitnamiHTTPS構成ツールを実行

sudo /opt/bitnami/bncert-tool

4. Bitnamiとの対話に答える

コマンド入力が必要なところに星をつけています。

bitnami@ip-xxx-xxx-xxx-xxx:~$ sudo /opt/bitnami/bncert-tool
★An updated version is available. Would you like to download it? You would need to run it manually later. [Y/n]: y

The tool will exit now. To run the updated version run the following command: 
/opt/bitnami/bncert-tool 
bitnami@ip-xxx-xxx-xxx-xxx:~$ sudo /opt/bitnami/bncert-tool
----------------------------------------------------------------------------
Welcome to the Bitnami HTTPS Configuration tool.
----------------------------------------------------------------------------
Domains
Please provide a valid space-separated list of domains for which you wish to 
configure your web server.
★Domain list []: (独自ドメイン)                        
★The following domains were not included: www.(独自ドメイン). Do you want to add them? [Y/n]: n

Warning: No www domains (e.g. www.example.com) or non-www domains (e.g. 
www.example.com) have been provided, so the following redirections will be 
disabled: non-www to www, www to non-www.
★Press [Enter] to continue:
----------------------------------------------------------------------------
Enable/disable redirections
Please select the redirections you wish to enable or disable on your Bitnami 
installation.
★Enable HTTP to HTTPS redirection [Y/n]: 

----------------------------------------------------------------------------
Changes to perform
The following changes will be performed to your Bitnami installation:
1. Stop web server
2. Configure web server to use a free Let's Encrypt certificate for the domains: 
(独自ドメイン)
3. Configure a cron job to automatically renew the certificate each month
4. Configure web server name to: (独自ドメイン)
5. Enable HTTP to HTTPS redirection (example: redirect http://(独自ドメイン) 
to https://(独自ドメイン))
6. Start web server once all changes have been performed

★Do you agree to these changes? [Y/n]: 


----------------------------------------------------------------------------
Create a free HTTPS certificate with Let's Encrypt
Please provide a valid e-mail address for which to associate your Let's Encrypt 
certificate.
Domain list: (独自ドメイン)
Server name: (独自ドメイン)
★E-mail address []:(メールアドレス)

The Let's Encrypt Subscriber Agreement can be found at:
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf
★Do you agree to the Let's Encrypt Subscriber Agreement? [Y/n]: y
----------------------------------------------------------------------------
Performing changes to your installation
The Bitnami HTTPS Configuration Tool will perform any necessary actions to your 
Bitnami installation. This may take some time, please be patient.
----------------------------------------------------------------------------
Success

5. HTTPS化を確認

実際にwebページにアクセスして、URLバーに南京錠マークが表示されていることを確認する。
スクリーンショット 2022-02-12 18.21.33.png

参考URL

Amazon LightsailでWebサイト構築(LAMP環境)

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