Overview
Install nginx to ubuntu 24.04
依存関係のインストール
.bash
sudo apt update
sudo apt install gnupg2 ca-certificates lsb-release ubuntu-keyring
署名キーをパッケージ認証のために取得
Import an official nginx signing key so apt could verify the packages authenticity
.bash
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
Verify that the downloaded file contains the proper key:
.bash
gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
The output should contain the full fingerprint:
.bash
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
nginx の安定版リポジトリをセットアップ
To set up the apt repository for stable nginx packages, run the following command:
.bash
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
Set up repository pinning to prefer our packages over distribution-provided ones:
.bash
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
| sudo tee /etc/apt/preferences.d/99nginx
nginx をインストール
.bash
sudo apt update
sudo apt install nginx
.bash
nginx -v
nginx version: nginx/1.28.0
sudo systemctl status nginx
[sudo] password for username:
○ nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: en>
Active: inactive (dead)
Docs: https://nginx.org/en/docs/
sudo systemctl start nginx
sudo systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: en>
Active: active (running) since Fri 2025-10-10 10:20:36 JST; 4s ago
......
...
参考