59
34

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

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

Last updated at Posted at 2020-07-30

はじめに

環境

  • 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:

59
34
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
59
34

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?