LoginSignup
2
0

More than 3 years have passed since last update.

EC2インスタンスをWebサーバとして起動し、Hello, worldを出力する

Last updated at Posted at 2021-01-05

はじめに

構造図

ssh接続.png

  • 例によってPrivate subnetは不要でもよい

image.png

手順

1. Apacheをインストールする

  • ターミナルを開く

  • ec2インスタンスにsshアクセスする

    • ssh -i ~/.ssh/develop.pem ec2-user@[パブリックIPv4アドレス]
  • 管理者権限に移動

    • sudo su
  • インストールされているソフトウェアを最新のものに更新

    • yum update -y
  • apacheサーバをインストール

    • yum install httpd -y

2. index.htmlを作成する

  • /var/www/htmlに移動
    • cd /var/www/html
  • htmlファイルを作る
  • vi index.html
    • 下記をコピー&ペースト
      • <html><h1>Hello, world!</h1></html>
    • 上書き保存
      • esc:wq
  • apacheを起動
    • systemctl start httpd
  • インスタンスの起動時にapacheが起動するように設定
    • systemctl enable httpd

3. ネットワークACL、セキュリティグループに設定を追加する

  • htmlを読み込むためにHTTP,HTTPSの設定を追加する

  • ネットワークACL

    • インバウンドルール(アウトバウンドルールも同様) image.png
  • セキュリティグループ

    • インバウンドルール(アウトバウンドルールは設定不要) image.png

4.ブラウザでインスタンスにアクセスする

  • EC2インスタンスのパブリックIPアドレスをコピー
  • 任意のブラウザでアドレスをペースト
  • Hello, world!が出力されれば成功

スクリーンショット 2021-01-05 22.31.00.png

完了

終わりに

  • EC2インスタンスは無料枠には時間制限があるので、使用しない場合は停止しておきましょう
  • 次回はStreamlitというPythonのAPIを使って、コロナウイルス感染者の人数を可視化するWebアプリケーションを作ってみます
  • 間違いや改善点等ございましたらコメントをいただければ幸いです

作図ツール

2
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
2
0