【2025 年 6 月版】 Amazon Linux 2023 に nginx をインストール
はじめに
Amazon Linux 2023 に nginx をインストールする手順を説明していきます。
環境 (バージョン)
- AMI
- Amazon Linux 2023
- nginx
- 1.28
2025/06/27 時点の環境で確認しています。
事前条件
Amazon Linux 2023 の EC2 インスタンスは起動済みとします。
Amazon Linux 2023 の起動方法、アクセス方法がわからない人は「AWS EC2」を学習しておいてください。
オススメの書籍は「Amazon Web Services 基礎からのネットワーク&サーバー構築 改訂 4 版」です。
PostgreSQL インストール
nginx はデフォルトのパッケージに含まれているので、パッケージからインストールします。
$ sudo dnf -y install nginx
Amazon Linux 2023 Kernel Livepatch repository 140 kB/s | 17 kB 00:00
Dependencies resolved.
=====================================================================================================================
Package Architecture Version Repository Size
=====================================================================================================================
Installing:
nginx x86_64 1:1.28.0-1.amzn2023.0.1 amazonlinux 33 k
Installing dependencies:
generic-logos-httpd noarch 18.0.0-12.amzn2023.0.3 amazonlinux 19 k
gperftools-libs x86_64 2.9.1-1.amzn2023.0.3 amazonlinux 308 k
libunwind x86_64 1.4.0-5.amzn2023.0.2 amazonlinux 66 k
nginx-core x86_64 1:1.28.0-1.amzn2023.0.1 amazonlinux 669 k
nginx-filesystem noarch 1:1.28.0-1.amzn2023.0.1 amazonlinux 9.5 k
nginx-mimetypes noarch 2.1.49-3.amzn2023.0.3 amazonlinux 21 k
Transaction Summary
=====================================================================================================================
Install 7 Packages
Total download size: 1.1 M
Installed size: 3.7 M
Downloading Packages:
(1/7): generic-logos-httpd-18.0.0-12.amzn2023.0.3.noarch.rpm 407 kB/s | 19 kB 00:00
(2/7): libunwind-1.4.0-5.amzn2023.0.2.x86_64.rpm 1.3 MB/s | 66 kB 00:00
(3/7): nginx-1.28.0-1.amzn2023.0.1.x86_64.rpm 1.4 MB/s | 33 kB 00:00
(4/7): gperftools-libs-2.9.1-1.amzn2023.0.3.x86_64.rpm 3.9 MB/s | 308 kB 00:00
(5/7): nginx-core-1.28.0-1.amzn2023.0.1.x86_64.rpm 15 MB/s | 669 kB 00:00
(6/7): nginx-filesystem-1.28.0-1.amzn2023.0.1.noarch.rpm 353 kB/s | 9.5 kB 00:00
(7/7): nginx-mimetypes-2.1.49-3.amzn2023.0.3.noarch.rpm 898 kB/s | 21 kB 00:00
---------------------------------------------------------------------------------------------------------------------
Total 8.7 MB/s | 1.1 MB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: nginx-filesystem-1:1.28.0-1.amzn2023.0.1.noarch 1/7
Installing : nginx-filesystem-1:1.28.0-1.amzn2023.0.1.noarch 1/7
Installing : nginx-mimetypes-2.1.49-3.amzn2023.0.3.noarch 2/7
Installing : libunwind-1.4.0-5.amzn2023.0.2.x86_64 3/7
Installing : gperftools-libs-2.9.1-1.amzn2023.0.3.x86_64 4/7
Installing : nginx-core-1:1.28.0-1.amzn2023.0.1.x86_64 5/7
Installing : generic-logos-httpd-18.0.0-12.amzn2023.0.3.noarch 6/7
Installing : nginx-1:1.28.0-1.amzn2023.0.1.x86_64 7/7
Running scriptlet: nginx-1:1.28.0-1.amzn2023.0.1.x86_64 7/7
Verifying : generic-logos-httpd-18.0.0-12.amzn2023.0.3.noarch 1/7
Verifying : gperftools-libs-2.9.1-1.amzn2023.0.3.x86_64 2/7
Verifying : libunwind-1.4.0-5.amzn2023.0.2.x86_64 3/7
Verifying : nginx-1:1.28.0-1.amzn2023.0.1.x86_64 4/7
Verifying : nginx-core-1:1.28.0-1.amzn2023.0.1.x86_64 5/7
Verifying : nginx-filesystem-1:1.28.0-1.amzn2023.0.1.noarch 6/7
Verifying : nginx-mimetypes-2.1.49-3.amzn2023.0.3.noarch 7/7
Installed:
generic-logos-httpd-18.0.0-12.amzn2023.0.3.noarch gperftools-libs-2.9.1-1.amzn2023.0.3.x86_64
libunwind-1.4.0-5.amzn2023.0.2.x86_64 nginx-1:1.28.0-1.amzn2023.0.1.x86_64
nginx-core-1:1.28.0-1.amzn2023.0.1.x86_64 nginx-filesystem-1:1.28.0-1.amzn2023.0.1.noarch
nginx-mimetypes-2.1.49-3.amzn2023.0.3.noarch
Complete!
インストール後に念のためバージョンを確認します。
$ nginx -v
nginx version: nginx/1.28.0
nginx を起動して、サーバー再起動時にも自動的に起動するようにします。
$ sudo systemctl start nginx
$ sudo systemctl enable nginx
セキュリティグループ確認
nginx の確認にて、EC2 インスタンスの 80 番ポートにアクセスするので、セキュリティグループで外部から 80 番ポートへのアクセスが許可されていることを確認します。
- EC2 のインスタンス一覧の画面で、今回構築した EC2 インスタンスを選択
- 「セキュリティ」タブを選択して、「セキュリティグループ」の ID をクリック
- 「インバウンドルール」をクリックして
- IP バージョン
- IPv4
- タイプ
- HTTP
- プロトコル
- TCP
- ポート範囲
- 80
の項目があることを確認します
- (ない場合) 「インバンドのルールを編集」-「ルールの追加」を順に押して、
- タイプ
- HTTP
- ソース
- Anywhere-IPv4
を選択して、「ルールの保存」を押します
nginx 確認
ブラウザのアドレスバーに「http://<EC2 の IP アドレス>」を入力して、「Welcome to nginx!」というページが表示されれば成功です。
デフォルトの設定ファイルでは /usr/share/nginx/html/index.html の内容が表示されます。
$ cat /usr/share/nginx/html/index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>