【AlmaLinux】Nginxのリポジトリを使用してインストール

AlmaLinx9にNginxのリポジトリを追加して、インストールを行う方法です。

作業手順

AlmaLinux9にNginxの公式で用意されているリポジトリを使用して、インストールする方法を説明していきます。

インストール作業は下記の流れで行っていきます。

  • Nginxリポジトリの追加
  • リポジトリの指定
  • インストール

Nginxリポジトリの追加

Nginxのリポジトリを/etc/yum.repos.d/nginx.repoという名前で作成します。

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

設定内容は以下になります。

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

[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

追加するリポジトリの内容は、下記ページの「RHEL and derivatives」部分に記載されています。

http://nginx.org/en/linux_packages.html

リポジトリの指定

作成したリポジトリの中には「nginx-stable」と「nginx-mainline」の2種類が記載されています。

初期設定では「nginx-stable」を使用する設定となっていますので、変更が必要ない場合はここの作業はスキップすることが出来ます。

「nginx-mainline」を使用してNginxをインストールしたい場合は、「dnf config-manager」で使用するリポジトリを「nginx-mainline」に設定してあげる必要があります。

mainlineとstableのどちらを使うか?

公式のページでは下記のように記載されています。

Choosing Between a Stable or a Mainline Version
NGINX Open Source is available in two versions:

Mainline – Includes the latest features and bug fixes and is always up to date. It is reliable, but it may include some experimental modules, and it may also have some number of new bugs.
Stable – Doesn’t include all of the latest features, but has critical bug fixes that are always backported to the mainline version. We recommend the stable version for production servers.

簡単に説明するとこんな感じになります。

  • mainline 最新の機能追加とバグ修正が行われているが、新しいバグがあるかもしれない
  • stable 重要なバグ修正のみなので、本番環境ではstableの使用を推奨

最新の機能やバグ修正が必要な場合はmainline版を使用し、最新の機能が必要なく安定をもとめる本番サーバではstable版を使用したほうが良いです。

stable版に最新機能が提供されない(APIに変更がない)のため、サードパーティモジュールへの動作に影響が発生しづらくなっています。

ちなみに、私はサードパーティのモジュールも使用しませんし、個人で運用しているwordpressに使っているだけなので、ほぼmainline版を使用しています。

dnf-utilsをインストール

使用するリポジトリを設定する際に「dnf config-manager」コマンドを使用するため、「dnf-utils」をインストールして「dnf config-manager」を使用できるようにします。

# dnf upgrade --refresh 
# dnf install -y dnf-utils

mainlineリポジトリの指定

mainlineリポジトリを使用したい場合は「dnf config-manager」で「nginx-mainline」を使用できるように設定を行います。

# dnf config-manager --enable nginx-mainline

インストール

dnfを使用してnginxのインストールを行います。

# dnf install -y nginx

正常にインストールされているかの確認を行います。

# nginx -v
nginx version: nginx/1.25.0

Nginxの起動と自動起動設定

Nginxの起動と自動起動の設定を行います。

# systemctl start nginx
# systemctl enable nginx

以上でインストール作業は完了です。

コメント

タイトルとURLをコピーしました