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?

On Ubuntu I noticed that diffy was starting up in my local environment on its own, so I stopped it.

Last updated at Posted at 2024-12-28

TL;DR

表題の問題を解消するために使用したコマンドは下記のとおりです

私の環境はUbuntu22.04です

3000ポートがローカルで起動している原因を確認するためのコマンド

sudo lsof -i :3000

ポート3000でどのプロセスが使用中かを確認します。

サービスの状態を確認するためのコマンド

systemctl status nghttpx.service

nghttpx が自動起動している場合、そのサービスの詳細を確認します。

サービスの自動起動を無効化するためのコマンド

sudo systemctl disable nghttpx.service

サービスがシステム起動時に自動的に起動しないよう設定します。

サービスを停止するためのコマンド

sudo systemctl stop nghttpx.service

現在稼働中の nghttpx サービスを停止します。

はじめに

昔に dify をDocker上で起動していたのですが、最近は一切起動をしていませんでした。

しかし、突如予期しないタイミングでローカルのポート3000で dify に関連する動作が確認されました。その原因が nghttpx にあると判明したため、停止および調査の手順を備忘録として残します。

執筆当時も原因が分かっていませんが、ローカル環境を色々整備していた際に不要な変更が追加されてしまったと推測しています。

調査手順

1. ポート3000の使用状況を確認

以下のコマンドを実行します。

sudo lsof -i :3000

なぜ実行するのか?

このコマンドは、ポート3000を現在使用しているプロセスを一覧表示します。具体的には、どのアプリケーションがリッスンしているのか、または接続を確立しているのかを特定するためです。

実行結果の例:

COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nghttpx   *** root    10u  IPv4  ****      ***  TCP localhost:3000 (LISTEN)

この結果から、nghttpx がポート3000を使用していることがわかりました。

2. サービスの状態を確認

以下のコマンドを実行します。

systemctl status nghttpx.service

なぜ実行するのか?

このコマンドは、nghttpx サービスが有効化されているかどうか、および現在の状態を確認するために使用します。稼働中であれば、自動起動の設定やエラーログも確認できます。

実行結果の例:

● nghttpx.service - HTTP/2 proxy
     Loaded: loaded (/lib/systemd/system/nghttpx.service; enabled; vendor preset: enabled)
     Active: active (running) since ...

この結果から、nghttpxenabledであり、システム起動時に自動的に起動する設定になっていることがわかります。

Enabling simply hooks the unit into various suggested places (for example, so that the unit is automatically started on boot or when a particular kind of hardware is plugged in).

停止手順

1. サービスの自動起動を無効化

以下のコマンドを実行します。

sudo systemctl disable nghttpx.service

なぜ実行するのか?

このコマンドは、システム起動時に nghttpx サービスが自動的に開始される設定を無効化します。次回以降の起動で、nghttpx が勝手に動作するのを防ぐためです。

実行結果の例:

Synchronizing state of nghttpx.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable nghttpx

2. サービスを停止

以下のコマンドを実行します。

sudo systemctl stop nghttpx.service

なぜ実行するのか?

現在アクティブな nghttpx サービスを即座に停止するために実行します。この操作により、ポート3000の使用が解除されます。

実行結果の例:

● nghttpx.service - HTTP/2 proxy
     Active: inactive (dead) since ...

まとめ

今回の調査および停止手順をまとめると、以下のステップで問題を解決できます:

  1. ポート使用状況の確認: lsof を使用して、ポート3000を使用しているプロセスを特定。
  2. サービスの状態確認: systemctl を使用して、nghttpx サービスの有効性と状態を確認。
  3. 自動起動の無効化: systemctl disable コマンドで、システム起動時の自動起動を無効化。
  4. サービスの停止: systemctl stop コマンドで、現在稼働中の nghttpx を停止。

これにより、予期しないポート3000の占有問題を解消しました。同様の状況が発生した場合には、上記の手順を参考にしてください。


おまけ: nghttpx 設定ファイルのバックアップと削除

上記の対応で十分だと思いましたが、
今回、nghttpx の予期しない動作を防ぐため、設定を削除する対応を行いました。

1. そもそもnghttpx とは何か:

nghttpx は、HTTP/2 および HTTP/3 に対応したプロキシです。

その設定ファイルである /etc/nghttpx/nghttpx.conf では、以下の内容をカスタマイズ可能です:

  • フロントエンド設定: クライアント接続の受け付けポートやアドレス。
  • バックエンド設定: リクエスト転送先のサーバー情報。
  • TLS設定: SSL/TLS の証明書や秘密鍵。

詳細な設定方法については、nghttpx - HTTP/2 proxy - HOW-TO — nghttp2 1.65.0-DEV documentation を参照してください。

2. 設定ファイルのバックアップと削除:

sudo cp /etc/nghttpx/nghttpx.conf ~/nghttpx.conf.bak
sudo rm /etc/nghttpx/nghttpx.conf

この操作により、nghttpx の設定ファイルを安全にバックアップした後、削除しました。

なぜこれを行うのか?:

設定ファイルを削除することで、nghttpx がデフォルト設定または無効状態となり、予期しない動作を防止します。

3. 設定ファイル削除の影響:

設定ファイルが削除されると、nghttpx は正常に動作しない場合があります。

必要に応じてバックアップを復元することで、元の設定を再適用できます。

sudo cp ~/nghttpx.conf.bak /etc/nghttpx/nghttpx.conf
sudo systemctl restart nghttpx.service
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?