#author("2025-03-20T03:50:24+09:00;2025-03-14T09:18:35+09:00","default:tanopro","tanopro") #author("2025-03-20T03:53:22+09:00;2025-03-14T09:18:35+09:00","default:tanopro","tanopro") #html{{ <h1 style="color: red; background-color: #FFFFCC; padding: 20px;"> Nginx(エンジンエックス) </h1> <div class="alert alert-warning" role="alert"> Webサーバーソフト </div> }} //---------------------------------------- #contents //---------------------------------------- //---------------------------------------- // 用語の定義 * Nginxとは? [#definition] - Nginx - Google 検索 https://www.google.com/search?q=Nginx - nginx - Wikipedia https://ja.wikipedia.org/wiki/Nginx >nginx(エンジンエックス)は、フリーでオープンソースなWebサーバアプリケーションである。 処理性能・高い並行性・少ないメモリ使用量を焦点に開発し、HTTP, HTTPS, SMTP, POP3, IMAPのリバースプロキシの機能や、ロードバランサ、HTTPキャッシュなどの機能も有する。 ** 公式サイト [#q29552bf] - nginx https://nginx.org/ - nginx · GitHub https://github.com/nginx //---------------------------------------- * Tips [#Tips] -[[Nginxのバーチャルホスト]] //---------------------------------------- * インストール [#w8d4e59e] Ubuntu 24.04 LTSにNginxをインストールするメモ。 ** aptコマンドでインストールできるバージョンの確認方法 [#w27eb1ea] *** 方法1: apt-cache policy コマンドを使用 [#a910f25d] apt-cache policy nginx 出力例 nginx: Installed: (none) Candidate: 1.24.0-2ubuntu1 Version table: 1.24.0-2ubuntu1 500 500 http://archive.ubuntu.com/ubuntu noble/main amd64 Packages - Candidate: インストールされる予定のバージョン - Version table: 利用可能なバージョンとリポジトリー情報 *** 方法2: apt list コマンドを使用 [#dd6534a5] apt list nginx 出力例 nginx/noble,now 1.24.0-2ubuntu1 amd64 [installed] 1.24.0-2ubuntu1 → 公式リポジトリーの最新の安定版 *** 方法3: apt show コマンドを使用 [#d2c2ce5b] apt show nginx 出力例 Package: nginx Version: 1.24.0-2ubuntu1 Priority: optional Section: web Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> - Version: に表示されているのがインストール可能なバージョン *** 方法4: grep を使ってバージョン一覧を取得 [#t2bdde44] apt-cache madison nginx 出力例 nginx | 1.24.0-2ubuntu1 | http://archive.ubuntu.com/ubuntu noble/main amd64 Packages 公式リポジトリーにあるバージョンが一覧表示されます。 //---------------------------------------- ** 方法1:Ubuntuの公式リポジトリーからインストールする方法 [#o9e2aba6] Ubuntuの公式リポジトリーには、ある程度新しいNginxの安定版が提供されています。 リポジトリーを追加せずにインストールできます。 *** 1. パッケージリストを更新 [#u8d3a612] sudo apt update *** 2. Nginxのインストール [#hc84c8af] sudo apt install -y nginx *** 3. インストールされたバージョンを確認 [#h1e03661] nginx -v *** 4. サービスを起動 [#gf3c8a89] sudo systemctl start nginx *** 5. 自動起動を有効化 [#c952aa75] sudo systemctl enable nginx ↓ Synchronizing state of nginx.service with SysV service script with /usr/lib/systemd/systemd-sysv-install. Executing: /usr/lib/systemd/systemd-sysv-install enable nginx ---- //---------------------------------------- ** 方法2:Nginx公式リポジトリーからインストールする方法(より新しい安定版を入手) [#ab3be89f] Ubuntuの公式リポジトリーのバージョンが古い場合、''Nginx公式リポジトリー''を追加すると、より新しい安定版をインストールできます。 *** 1. 依存パッケージをインストール [#y839a511] sudo apt install -y curl gnupg2 ca-certificates lsb-release *** 2. Nginxの公式GPGキーを追加 [#v7d3e137] curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo gpg --dearmor -o /usr/share/keyrings/nginx-archive-keyring.gpg *** 3. リポジトリーを追加 [#f96e440a] 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 *** 4. パッケージリストを更新 [#zfbf05fa] sudo apt update *** 5. 既存のNginxを削除(公式リポジトリーのものを入れ替える場合) [#t1cff167] sudo apt remove -y nginx nginx-common *** 6. Nginxのインストール [#idea0a79] sudo apt install -y nginx *** 7. バージョン確認 [#s8442f94] nginx -v *** 8. サービスの起動と自動起動設定 [#tf39460f] sudo systemctl start nginx sudo systemctl enable nginx ---- ** どちらを選ぶべきか? [#xad19204] - ''Ubuntu公式リポジトリー''(方法1)は、安定性が最も重視されており、Ubuntuのアップデートと連携しやすい。 - ''Nginx公式リポジトリー''(方法2)は、より新しいバージョンを利用したい場合に適している。 最新の安定版を使いたい場合は、方法2(Nginx公式リポジトリー追加)を選ぶのが良いでしょう。 //---------------------------------------- * Nginxの動作確認 [#y53ad98a] Nginxの稼働状況を確認します。 sudo systemctl status nginx 出力例 ● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: enabled) Active: active (running) since Thu 2025-03-20 02:27:46 JST; 1h 19min ago Docs: man:nginx(8) Process: 79349 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (> Process: 79352 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exit> Main PID: 79353 (nginx) Tasks: 5 (limit: 4612) Memory: 3.8M (peak: 4.6M) CPU: 24ms CGroup: /system.slice/nginx.service ├─79353 "nginx: master process /usr/sbin/nginx -g daemon on; master_process> ├─79354 "nginx: worker process" ├─79355 "nginx: worker process" ├─79356 "nginx: worker process" └─79357 "nginx: worker process" Mar 20 02:27:46 vm-2d04dfa6-71 systemd[1]: Starting nginx.service - A high performance web server and a reverse proxy server... Mar 20 02:27:46 vps-vm systemd[1]: Starting nginx.service - A high performance web server and a reverse proxy server... というように「Active: active (running)」と表示されていればOKです。 //---------------------------------------- // *Amazon [#amazon] #html{{ }} //---------------------------------------- * 関連 [#wcee1933] //---------------------------------------- // -[[]]