Skip to content

Ubuntu 24.04LTS へ Nginx をインストールする

以前に以下のメモを書きました。

Ubuntu 24.04LTS でもインストールコマンドは全く同じなのですが、改めてメモしておきます。 正式な手順は Installation instructions に掲載されています。 コマンド自体は全く同じですが、公式ページでは手順が複数ステップに分割して記載されている為、このメモでは「そのまま流し込めるように」コマンドを連結しています。

検証環境

対象 バージョン
Ubuntu 24.04LTS

Nginx 公式リポジトリから Nginx 安定版をインストールする

Nginx 公式リポジトリを追加し、Nginx の安定版をインストールするには以下を実行します。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
sudo apt install -y curl gnupg2 ca-certificates lsb-release ubuntu-keyring && \
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null && \
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list && \
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
    | sudo tee /etc/apt/preferences.d/99nginx && \
sudo apt update && \
sudo apt install -y nginx && \
sudo systemctl start nginx && \
sudo systemctl enable nginx

Apach 風ドキュメントルートのリンクを追加する

Apache 風のドキュメントルートとして /var/www/html も使えるようにシンボリックリンクを作成します。

mkdir -p /var/www/
rm -rf /var/www/html/*
ln -s /usr/share/nginx/html /var/www/

インストール可能な Nginx バージョン

インストール可能な Nginx バージョンは以下でした。 Nginx 公式リポジトリからインストール可能なバージョンは 1.26.1 でした。 Ubuntu の標準リポジトリからインストール可能なバージョンは 1.24.0 であることが分かります。

# apt info -a nginx
Package: nginx
Version: 1.26.1-2~noble
Priority: optional
Section: httpd
Maintainer: NGINX Packaging <nginx-packaging@f5.com>
Installed-Size: 3640 kB
Provides: httpd, nginx, nginx-r1.26.1
Depends: libc6 (>= 2.34), libcrypt1 (>= 1:4.1.0), libpcre2-8-0 (>= 10.22), libssl3t64 (>= 3.0.0), zlib1g (>= 1:1.1.4), lsb-base (>= 3.0-6)
Recommends: logrotate
Conflicts: nginx-common, nginx-core
Replaces: nginx-common, nginx-core
Homepage: https://nginx.org
Download-Size: 1125 kB
APT-Manual-Installed: yes
APT-Sources: http://nginx.org/packages/ubuntu noble/nginx amd64 Packages
Description: high performance web server
 nginx [engine x] is an HTTP and reverse proxy server, as well as
 a mail proxy server.

Package: nginx
Version: 1.26.1-1~noble
Priority: optional
Section: httpd
Maintainer: NGINX Packaging <nginx-packaging@f5.com>
Installed-Size: 3639 kB
Provides: httpd, nginx, nginx-r1.26.1
Depends: libc6 (>= 2.34), libcrypt1 (>= 1:4.1.0), libpcre2-8-0 (>= 10.22), libssl3t64 (>= 3.0.0), zlib1g (>= 1:1.1.4), lsb-base (>= 3.0-6)
Recommends: logrotate
Conflicts: nginx-common, nginx-core
Replaces: nginx-common, nginx-core
Homepage: https://nginx.org
Download-Size: 1125 kB
APT-Sources: http://nginx.org/packages/ubuntu noble/nginx amd64 Packages
Description: high performance web server
 nginx [engine x] is an HTTP and reverse proxy server, as well as
 a mail proxy server.

Package: nginx
Version: 1.26.0-1~noble
Priority: optional
Section: httpd
Maintainer: NGINX Packaging <nginx-packaging@f5.com>
Installed-Size: 3635 kB
Provides: httpd, nginx, nginx-r1.26.0
Depends: libc6 (>= 2.34), libcrypt1 (>= 1:4.1.0), libpcre2-8-0 (>= 10.22), libssl3t64 (>= 3.0.0), zlib1g (>= 1:1.1.4), lsb-base (>= 3.0-6)
Recommends: logrotate
Conflicts: nginx-common, nginx-core
Replaces: nginx-common, nginx-core
Homepage: https://nginx.org
Download-Size: 1125 kB
APT-Sources: http://nginx.org/packages/ubuntu noble/nginx amd64 Packages
Description: high performance web server
 nginx [engine x] is an HTTP and reverse proxy server, as well as
 a mail proxy server.

Package: nginx
Version: 1.24.0-2ubuntu7
Priority: optional
Section: web
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Nginx Maintainers <pkg-nginx-maintainers@alioth-lists.debian.net>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 1352 kB
Provides: httpd, httpd-cgi, nginx-abi-1.24.0-1
Depends: libc6 (>= 2.34), libcrypt1 (>= 1:4.1.0), libpcre2-8-0 (>= 10.22), libssl3 (>= 3.0.0), zlib1g (>= 1:1.1.4), iproute2, nginx-common (= 1.24.0-2ubuntu7)
Breaks: nginx-core (<< 1.22.1-6~), nginx-extras (<< 1.22.1-6~), nginx-light (<< 1.22.1-6~)
Replaces: nginx-core (<< 1.22.1-6~), nginx-extras (<< 1.22.1-6~), nginx-light (<< 1.22.1-6~)
Homepage: https://nginx.org
Download-Size: 521 kB
APT-Sources: http://archive.ubuntu.com/ubuntu noble/main amd64 Packages
Description: small, powerful, scalable web/proxy server
 Nginx ("engine X") is a high-performance web and reverse proxy server
 created by Igor Sysoev. It can be used both as a standalone web server
 and as a proxy to reduce the load on back-end HTTP or mail servers.