24
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

posted at

updated at

AWS EC2にNginxをインストールする

はじめに

環境

  • EC2インスタンス作成済み
    • Amazon Linux 2 AMI (HVM), SSD Volume Type
    • 64 ビット (x86)
    • タイプ:t2.micro

やったこと

EC2サーバーでの操作

接続

$ ssh -i xxxx.pem ec2-user@パブリックIP(またはDNS)

amazon-linux-extrasの確認

amazon-linux-extrasを使ってインストールできるパッケージの確認をします。

$ which amazon-linux-extras
$ amazon-linux-extras

  0  ansible2                 available    [ =2.4.2  =2.4.6  =2.8  =stable ]
  2  httpd_modules            available    [ =1.0  =stable ]
  3  memcached1.5             available    [ =1.5.1  =1.5.16  =1.5.17 ]
  5  postgresql9.6            available    [ =9.6.6  =9.6.8  =stable ]
  6  postgresql10             available    [ =10  =stable ]
  8  redis4.0                 available    [ =4.0.5  =4.0.10  =stable ]

   ...略

 38  nginx1                   available    [ =stable ]
 39  ruby2.6                  available    [ =2.6  =stable ]
 40  mock                     available    [ =stable ]
 41  postgresql11             available    [ =11  =stable ]

   ... 略

参考:
amazon-linux-extrasについて
https://aws.amazon.com/jp/premiumsupport/knowledge-center/ec2-install-extras-library-software/

Nginxのインストール

$ sudo amazon-linux-extras install nginx1

$ nginx -v
nginx version: nginx/1.18.0

初期設定ファイルのバックアップ

$ sudo cp -a /etc/nginx/nginx.conf /etc/nginx/nginx.conf.back

起動設定

Nginx起動

$ sudo systemctl start nginx

インスタンス起動時にNginxも自動で起動させる

$ sudo systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

設定確認

$ systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/nginx.service.d
           └─php-fpm.conf
   Active: active (running) since 木 2020-07-30 14:34:02 JST; 1min 20s ago

ブラウザで確認

EC2接続時に使用したパブリックIP(またはDNS)をアドレスバーに入力して接続します。
スクリーンショット 2020-07-30 15.13.39.png

「正しくインストールできています」のページが表示されました:thumbsup::thumbsup::thumbsup:

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
24
Help us understand the problem. What are the problem?