NGINXが起動しない

こんにちは、皆さん!

サブドメインに Discourse をインストールしようとしています。
メインドメインは Docker Compose を使用して構築された WordPress が稼働しています。
サブドメインとドメインは同じ VPS サーバーを使用しています。
インストールにあたっては、こちらのガイドに従いました: https://meta.discourse.org/t/run-other-websites-on-the-same-machine-as-discourse/17247

残念ながら、NGINX が起動しません。 systemctl status nginx コマンドを実行すると、以下のメッセージが表示されます。

× nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2024-03-08 07:06:36 CST; 1h 14min ago
       Docs: man:nginx(8)
    Process: 27329 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 27330 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
        CPU: 42ms

Mar 08 07:06:33 vmi1695712.contaboserver.net systemd[1]: Starting A high performance web server and a reverse proxy server...
Mar 08 07:06:33 vmi1695712.contaboserver.net nginx[27330]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
Mar 08 07:06:34 vmi1695712.contaboserver.net nginx[27330]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
Mar 08 07:06:34 vmi1695712.contaboserver.net nginx[27330]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
Mar 08 07:06:35 vmi1695712.contaboserver.net nginx[27330]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
Mar 08 07:06:35 vmi1695712.contaboserver.net nginx[27330]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
Mar 08 07:06:36 vmi1695712.contaboserver.net nginx[27330]: nginx: [emerg] still could not bind()
Mar 08 07:06:36 vmi1695712.contaboserver.net systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Mar 08 07:06:36 vmi1695712.contaboserver.net systemd[1]: nginx.service: Failed with result 'exit-code'.
Mar 08 07:06:36 vmi1695712.contaboserver.net systemd[1]: Failed to start A high performance web server and a reverse proxy server.

Discourse 用のサイトファイルは以下の通りです。

# Default server configuration
#
server {
        # listen 80 default_server;
        # listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name forum.ictsharks.com;

        location / {
                proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:;
                proxy_set_header Host $http_host;
                proxy_http_version 1.1;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Real-IP $remote_addr;
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                # try_files $uri $uri/ =404;
        }

        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}

何度か確認しましたが、エラーの原因がわかりません。
Linux / NGINX / Docker の初心者で申し訳ありません。何かアドバイスをいただけると幸いです。よろしくお願いします。

「いいね!」 1

そのマシンには、ポート80を占有している別のウェブサーバーがありますか?

「いいね!」 1

app.yml のポートを変更して、Discourse が NGINX が使用したいポートを使用しようとしないようにしましたか?

これは、DNS、HTTPS および証明書、nginx、リバース プロキシ、docker、およびルーティングに関する理解が必要な高度なセットアップです。

「いいね!」 1

前述したように、WordPressはメインドメインで実行されています。

私の理解が正しければ、他のNGINXはWordPressと共にコンテナ内で動作しています。

このチュートリアルに従いました: How To Install WordPress With Docker Compose | DigitalOcean

netstat -tulnp コマンドを実行すると、次の結果が得られます。

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      419/systemd-resolve
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1192/docker-proxy
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      463/sshd: /usr/sbin
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      1179/docker-proxy
tcp6       0      0 :::22                   :::*                    LISTEN      463/sshd: /usr/sbin
udp        0      0 127.0.0.53:53           0.0.0.0:*                           419/systemd-resolve

指示通りコメントアウトしました。

## このコンテナが公開すべきTCP/IPポートはどれですか?
## Apacheやnginxのような他のウェブサーバーとポートを共有したい場合は、
## 詳細については https://meta.discourse.org/t/17247 を参照してください。
expose:
  # - "80:80"   # http
  # - "443:443" # https

DNSレコード、https、証明書は理解しています。それ以外はすべて初めてです。

心配しないでください。私はGoogle検索の方法を知っていますし、学習も速いです :wink:

「いいね!」 1

これを開始する前に、WordPressは機能しているNGINXリバースプロキシの後ろにあり、そこにDiscourseを追加していましたか?

それとも、以前Apache/WordPressが実行されていて、それがポート80を使用していたのですか?

ああ、docker-proxyがポート80を使用しているようですね。もしかしたら、WordPressをdocker-proxyの後ろに置いていましたか?

もしかしたらdocker psで、何がdockerか確認できるかもしれません。

「いいね!」 1

私が述べたように、他のNGIX(WordPress用)はMySQLおよびWordPressと一緒にコンテナ内で動作していると信じています。

これはdocker psコマンドを実行した結果です。

CONTAINER ID   IMAGE                        COMMAND                  CREATED          STATUS          PORTS                                      NAMES
6ca4cbec2c88   local_discourse/app          "\"/sbin/boot\""          51 minutes ago   Up 15 minutes                                              app
4a3ebdd9f5b5   nginx:1.15.12-alpine         "nginx -g 'daemon of…"   20 hours ago     Up 15 minutes   0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   webserver
42c4211a2fb6   wordpress:5.1.1-fpm-alpine   "docker-entrypoint.s…"   2 days ago       Up 15 minutes   9000/tcp                                   wordpress
5b588a7435ad   mysql:8.0                    "docker-entrypoint.s…"   2 days ago       Up 15 minutes   3306/tcp, 33060/tcp                        db

それゆえ、外部のnginxが起動できないのでしょう。ポートが内部のnginxによって使用されているからです。そのコンテナをシャットダウンし、WordPressの設定を外部のnginxレイヤーに移行する必要があるでしょう。

また、これらは別々のコンテナであり、nginxはMySQLやWordPressとは別です。

「いいね!」 1

ウェブサーバー(NGINXコンテナ)をシャットダウンし、外部NGINXを起動しようとしましたが、まだ機能しません。

おっしゃる通りです。私の間違いでした。言及されているすべてのアプリが1つのコンテナに入っていると思っていました。

コンテナ1つ=アプリケーション/プログラム1つ :wink:

docker psnetstat -tulnp は現在どのようになっていますか?

CONTAINER ID   IMAGE                        COMMAND                  CREATED       STATUS       PORTS                 NAMES
6ca4cbec2c88   local_discourse/app          “/sbin/boot”             3時間前       2時間稼働中                         app
42c4211a2fb6   wordpress:5.1.1-fpm-alpine   “docker-entrypoint.s…”   2日前       2時間稼働中   9000/tcp              wordpress
5b588a7435ad   mysql:8.0                    “docker-entrypoint.s…”   2日前       2時間稼働中   3306/tcp, 33060/tcp   db

アクティブなインターネット接続(サーバーのみ)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      418/systemd-resolve
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      462/sshd: /usr/sbin
tcp6       0      0 :::22                   :::*                    LISTEN      462/sshd: /usr/sbin
udp        0      0 127.0.0.53:53           0.0.0.0:*                           418/systemd-resolve

他にできることはあまりありませんが、nginx はまだ同じことをしているように見えますか、それともエラーは変化しましたか?

これは web.socketed.template.yml テンプレートを追加することと併せて行うべきですが、あなたはそれをしましたか?

「いいね!」 2

はい、そうしました。

NGINXのアンインストールと再インストールを試み、設定ファイルを削除しましたが、問題は解決しません。

NGINXのエラーを調べて、何が見つかるか確認してみます。

NGINXの問題を解決しました!:grinning:

/etc/nginx/sites-enabled/フォルダに、意味不明な「ysystemctl status nginx」ファイルがありました。それを削除しました。

これでNGINXは動作します :muscle:

rikingさんの指示に従って、結果をお知らせします。

「いいね!」 1

承知いたしました。ディスコースフォーラムが稼働しました!

残念ながら、WordPress/ウェブサイトを実行しているNGINXの設定を変更する方法については、説明に記載されていません。

記載されているのは次のとおりです。他のNGINX「サイト」を作成し、上記の最後のステップのようにそれらをリンクして有効にします。

これを達成する方法について、何かヒントをいただけると大変助かります。

WordPressは、このガイドに従ってインストールしました。Docker ComposeでWordPressをインストールする方法

それ以外に、私の推論を確認または否定していただけますか?

  1. NGINX(コンテナ外のもの)はリバースプロキシとして使用されます。
  2. NGINX(コンテナ外のもの)は、「アウターNGINX」と呼ばれます。
  3. NGINX(コンテナ外のもの)は、現在のセットアップではTCPポートではなくUnixソケットを使用して通信します。
  4. ディスコースはスタンドアロンアプリケーションであるため、独自のNGINXウェブサーバーをインストールする必要はありません。

明白なことを確認しようとしているのであれば、お詫び申し上げます。100%明確にしたいだけです。

それがほぼ全てです。

Discourseコンテナには、nginx、rails、postgres、redisが含まれています。

「いいね!」 1