Unix:/var/discourse/shared/standalone/nginx.http.sock (2: 該当するファイルまたはディレクトリがありません) [解決済み]

みなさん、こんにちは。

ウェブサイトで 502 Bad Gateway エラーが発生し、nginx.http.sock の問題が解決できません。

Nginx error.log

[crit] 14339#14339: *1 connect() to unix:/var/discourse/shared/standalone/nginx.http.sock failed (2: No such file or directory) while connecting to upstream, client: **.***.***.***, server: mydomain.net, request: "GET / HTTP/2.0", upstream: "http://unix:/var/discourse/shared/standalone/nginx.http.sock:/", host: "mydomain.net", referrer: "https:/mydomain.net/" "

以下が discourse.conf です。

server {
    listen 80;
    listen [::]:80;
    server_name mydmain.net www.mydomain.net;  # <-- ここを変更

}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name mydomain www.mydomain.net;  # <-- ここを変更

    ssl on;
    ssl_certificate /etc/letsencrypt/live/mydomain.net/fullchain.pem; # Certbot によって管理されています
    ssl_certificate_key /etc/letsencrypt/live/mydomain.net/privkey.pem; # Certbot によって管理されています
    ssl_dhparam /etc/letsencrypt/live/mydomain.net/dhparams.pem;
    include /etc/nginx/snippets/ssl.conf;

    http2_idle_timeout 5m; # デフォルトの 3m から 5m に変更

    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 https;
        proxy_set_header X-Real-IP $remote_addr;

    }
}

my app.yml

templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/sshd.template.yml"
  - "templates/web.ratelimited.template.yml"
## Lets Encrypt (https) を追加したい場合は、以下の 2 行のコメントを外してください
  - "templates/web.ssl.template.yml"
  - "templates/web.letsencrypt.ssl.template.yml"
##  - "templates/web.socketed.template.yml"
## このコンテナが公開すべき TCP/IP ポートはどれですか?
## Discourse を Apache や nginx などの他のウェブサーバーとポートを共有したい場合は、
## https://meta.discourse.org/t/17247 を参照してください
#expose:
# - "2045:80"   # http
# - "1443:443" # https

“templates/web.socketed.template.yml” のコメントを外してみましたが、Nginx のエラーログには同じ結果が表示されます。この問題を解決するにはどうすればよいでしょうか?もうアイデアが尽きてしまいました。お手数ですが、ご協力をお願いいたします ;/

私は専門家ではありませんが、もし私の認識が間違っていなければ、ソケット方式を採用する場合は、web.socketed.template のコメントアウトを外す必要があるでしょう。

もうやりましたけど、同じ結果になります。

私の環境でも試してみました(以前はポートをリッスンする方法を使っていましたが)、問題なく動作します。

以下の点を確認してください:

  • SSL/Let’s Encrypt のテンプレートはコメントアウトしてください。これは外部の Nginx 設定で既に処理されています。
  • アプリを再ビルドして、/var/discourse/shared/standalone/nginx.http.sock ファイルが表示されるようにしてください。

必ず確認してください

  • SSL/Let’s Encrypt のテンプレートはコメントアウトされていること(外部の Nginx 設定で既に処理されているため)。
  • アプリを再ビルドして、nginx.http.sock ファイルが /var/discourse/shared/standalone/ に表示されるようにすること。

はい、ではこの行はどうなるのでしょうか?502 ゲートウェイエラーは消え、ウェブサイトは起動していますが、この行のために同じ Nginx エラーが表示されます。

location / {
        proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock;

SSL が機能していないようで、画像も表示されません。フォーラムの設定時にロゴをアップロードしました

まだ行っていない場合は、Discourse のオプション「force https」を有効にしてください(セキュリティタブ)

OMGGG!!! ありがとうございます <3。果物を奢りますよ :smiley:。で、SMTP の設定方法を調べないと。Yandex だと動かなかったし、テストユーザーの登録時にメールが届かないんです。

上記の提案をすべて試しましたが、まだ 502 Bad Gateway エラーが発生しています。現在は HTTPS を使用していません。

エラー内容は以下の通りです:

> 2020/04/02 00:17:54 [crit] 18599#18599: *1 connect() to unix:/var/discourse/shared/standalone/nginx.http.sock failed (2: No such file or directory) while connecting to upstream, client: xx.xxx.xxx.xx, server: talk.mydomain.com, request: "GET / HTTP/1.1", upstream: "http://unix:/var/discourse/shared/standalone/nginx.http.sock:/", host: "talk.mydomain.com"
> 
> 2020/04/02 00:17:54 [crit] 18599#18599: *1 connect() to unix:/var/discourse/shared/standalone/nginx.http.sock failed (2: No such file or directory) while connecting to upstream, client: xx.xxx.xxx.xx, server: talk.mydomain.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://unix:/var/discourse/shared/standalone/nginx.http.sock:/favicon.ico", host: "talk.mydomain.com", referrer: "http://talk.mydomain.com/"

以下は /etc/nginx/sites-enabled/discourse.conf ファイルの内容です:

server {
        listen 80; listen [::]:80;
        server_name talk.mydomain.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;
        }
}

以下は /var/discourse/containers/app.yml のテンプレートセクションです:

server {
        listen 80; listen [::]:80;
        server_name talk.mydomain.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;
        }
}

ご教示ください。