0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Rocky Linux 8でnginxを1.31.xにバージョンアップする手順【脆弱性対応】

0
Posted at

はじめに

2026年5月、nginxにいくつかの脆弱性が公開されました。

参考:Webサーバー「nginx」にセキュリティ更新、「njs」には致命的な脆弱性も - 窓の杜

今回のアップデートで対処された主な脆弱性は以下の通りです。

CVE 概要 深刻度
CVE-2026-42945 ngx_http_rewrite_moduleのバッファオーバーフロー Medium(NVD評価ではCritical / CVSS 9.2)
CVE-2026-42926 ngx_http_proxy_moduleのHTTP/2リクエストインジェクション Medium
CVE-2026-42946 ngx_http_scgi_module等のバッファオーバーリード Medium
CVE-2026-40701 OCSPにおけるresolverのuse-after-free Medium
CVE-2026-8711 njs(ngx_http_js_module)のヒープバッファオーバーフロー Critical(CVSS 9.2)

特にCVE-2026-42945は、rewriteディレクティブやsetディレクティブを使っているサーバーに対して、認証なしのリモートコード実行が可能になる恐れがある深刻なものです。対応バージョンはstableの1.30.1以降、またはmainlineの1.31.0以降です。

この記事では、Rocky Linux 8でdnfを使ってnginxをインストールしている環境を対象に、バージョンアップ手順を実際の作業ログとともに解説します。


前提知識:Rocky Linux 8のnginxとリポジトリの話

Rocky Linux 8のデフォルトリポジトリ(AppStream)に含まれているnginxは1.14.1です。これは古く、今回の脆弱性対応バージョン(1.30.1 / 1.31.x)には到達できません。

1.31.xにバージョンアップするには、nginx公式リポジトリを追加する必要があります。

nginxのブランチについて

nginx公式には2種類のブランチがあります。

ブランチ 特徴 対応バージョン例
stable 安定性重視。本番環境向け 1.30.x
mainline 最新機能を含む。1.31.xはこちら 1.31.x

今回の脆弱性対応として1.31.xを選択する場合はmainlineリポジトリを追加する必要があります。stable(1.30.x)でもCVE対応済みなので、安定性を重視するならstableを選ぶのも合理的です。


環境

  • OS:Rocky Linux 8
  • 現在のnginxバージョン:1.14.1(AppStreamリポジトリからインストール済み)
  • インストール方法:dnf

手順

Step 1:現状確認

まず現在のバージョンとインストール元を確認します。

nginx -v
rpm -qi nginx | grep -E "Version|From repo"

実行結果:

nginx version: nginx/1.14.1
Version     : 1.14.1
From repo   : @appstream

@appstream と表示されていれば、AppStreamリポジトリからインストールされています。


Step 2:nginx公式リポジトリを追加

AppStreamの1.14.1から新バージョンへ上げるには、nginx公式リポジトリの追加が必要です。

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

mainline(1.31.x)を使う場合:

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

stable(1.30.x)を使う場合:

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

Step 3:AppStreamのnginxモジュールを無効化

AppStreamとnginx公式リポジトリの競合を防ぐために無効化します。

dnf module disable nginx

実行結果:

Disabling modules:
 nginx
Complete!

⚠️ 警告メッセージについて
実行時に以下のような警告が表示されることがありますが、無視して問題ありません。

Problem: module php:7.2 requires module(nginx), but none of the providers can be installed

PHPモジュールの依存関係に関する警告で、処理は正常に Complete! で終了します。


Step 4:インストール可能なバージョンを確認

dnf list --showduplicates nginx

nginx公式リポジトリのパッケージが Available Packages に表示されることを確認します。

Available Packages
nginx.x86_64    1:1.31.0-1.el8.ngx    nginx-mainline
nginx.x86_64    1:1.31.1-1.el8.ngx    nginx-mainline
...

Step 5:バージョンアップ実行

dnf upgrade nginx

初回実行時はGPGキーのインポート確認が表示されます。内容を確認して y を入力します。

Importing GPG key 0xB49F6B46:
 Userid     : "nginx signing key <signing-key-2@nginx.com>"
 Fingerprint: 8540 A6F1 8833 A80E 9C16 53A4 2FD2 1310 B49F 6B46
Is this ok [y/N]: y

特定バージョンを指定したい場合:

dnf install nginx-1:1.31.1-1.el8.ngx

Step 6:バージョンアップ後の確認

バージョン確認

nginx -v
nginx version: nginx/1.31.1

設定ファイルの構文チェック

nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

サービス再起動と動作確認

systemctl restart nginx
systemctl status nginx
curl -I http://localhost
HTTP/1.1 200 OK
Server: nginx/1.31.1

⚠️ reload ではなく restart を使うこと
バージョンアップ後は systemctl reload nginx ではなく systemctl restart nginx を使ってください。
reload は設定ファイルの再読み込みのみで、バイナリ自体は置き換わりません。reload だけだと curl -I のレスポンスが旧バージョンのままになることがあります。


ロールバック手順

万が一問題が発生した場合は以下でダウングレードできます。

# 1つ前のバージョンに戻す
dnf downgrade nginx

# サービス再起動
systemctl restart nginx

# バージョン確認
nginx -v

バージョン固定(任意)

バージョンアップ後、意図しないアップデートを防ぎたい場合はversionlockで固定できます。

# プラグインのインストール
dnf install python3-dnf-plugin-versionlock

# バージョン固定
dnf versionlock nginx

# 固定解除
dnf versionlock delete nginx

まとめ

Rocky Linux 8でのnginxバージョンアップのポイントをまとめます。

  • AppStreamリポジトリのnginxは1.14.1止まりのため、新バージョンにはnginx公式リポジトリの追加が必要
  • 1.31.xはmainlineブランチのため、mainlineのrepoファイルを作成する
  • AppStreamのnginxモジュールは必ず無効化する(競合防止)
  • バージョンアップ後のサービス再起動は restart を使う(reload では不十分)
  • 今回の脆弱性(特にCVE-2026-42945)はrewriteディレクティブを使っているサーバーが対象のため、設定を確認した上で早急に対応することを推奨します

参考リンク

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?