スズハドットコム

IT関連や3Dプリンタの記事、たまに生活のメモを書いていきます。

AlmaLinuxにnginxをインストール

環境

AlmaLinux 8.5 x86_64

インストール手順(nginx公式リポジトリから)

リポジトリの作成

最新版をインストールするため、公式リポジトリを追加します。
作業前のリポジトリファイル群はこんな感じ。ここにファイルを1つ追加します。

# ls -l /etc/yum.repos.d/
合計 20
-rw-r--r--. 1 root root  951 12月 22 04:51 almalinux-ha.repo
-rw-r--r--. 1 root root  893 12月 22 04:51 almalinux-plus.repo
-rw-r--r--. 1 root root  971 12月 22 04:51 almalinux-powertools.repo
-rw-r--r--. 1 root root 1049 12月 22 04:51 almalinux-resilientstorage.repo
-rw-r--r--. 1 root root 2690 12月 22 04:51 almalinux.repo

リポジトリファイルを新規作成します。

# vi /etc/yum.repos.d/nginx.repo

内容は公式サイトの説明のとおり。

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

リポジトリを有効化します。

# dnf config-manager --enable nginx-mainline
# dnf makecache
AlmaLinux 8 - BaseOS                                                                    3.5 kB/s | 4.3 kB     00:01
AlmaLinux 8 - AppStream                                                                 5.4 kB/s | 4.7 kB     00:00
AlmaLinux 8 - Extras                                                                    4.5 kB/s | 3.9 kB     00:00
nginx mainline repo                                                                      59 kB/s |  95 kB     00:01
メタデータキャッシュを作成しました。

インストール

nginxのパッケージ情報を表示してみます。 nginx-mainlineリポジトリからバージョン1.21.6がインストールされるようです。

# dnf info nginx
(略)
名前         : nginx
エポック     : 1
バージョン   : 1.21.6
(略)

インストールを実行します。

# dnf install nginx

起動

インストールしただけではnginxは無効状態です。

# systemctl status nginx
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: http://nginx.org/en/docs/

有効化、起動します。

# systemctl enable nginx
# systemctl start nginx
# systemctl status nginx
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2022-01-30 15:45:22 JST; 3s ago
(略)

サーバ自身のブラウザで、 http://localhost にアクセスしてみます。
このようなページが表示されれば成功です。
※この時点ではファイアウォールのポートが開いてないので、別のPCから表示確認はできないはずです。

(参考)ファイアウォールの開け方
現在許可されているサービスを確認

# firewall-cmd --list-services --zone=public

httpを追加

# firewall-cmd --add-service=http --zone=public --permanent

リロードして設定を反映

# firewall-cmd --reload

変更結果を確認(httpが追加されたはず)

# firewall-cmd --list-services --zone=public