サブフォルダインストール時の404エラー(アセット)

Discourse が、5 月 15 日頃に自動アップグレードページでコマンドラインからのアップグレードを求められた後に「git pull」を実行し、その後「rebuild」を行ったところ、アセットファイル(css/js など)で 404 エラーが発生するようになってから、ちょうど 1 ヶ月が経過しました。

それから数日後の今日、再度再インストールを試みましたが、数日経っても状況は変わっていません。私の app.yml ファイルの内容は以下の通りです。

##
## このファイルに変更を加えた後、ライブの Discourse インスタンスに変更を反映させるには、
## 必ず rebuild を実行する必要があります:
##
## /var/discourse/launcher rebuild app
##
## YAML 構文に従ってください。確認にはこのサイトが役立ちます:
## http://www.yamllint.com/

## これはオールインワンのスタンドアロン Discourse Docker コンテナテンプレートです

# web.ratelimited テンプレートのコメントアウトを外すことで、レート制限を追加できます。
# デフォルトでは IP 当たり秒間 12 リクエスト、IP 当たり分間 100 リクエストが許可されます。
# このファイルのパラメータを変更することで設定可能です。

templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"

expose:
  - "25654:80"
  # - "80:80"
  # - "2222:22"

params:
  db_default_text_search_config: "pg_catalog.english"
  version: tests-passed

env:
  LANG: en_US.UTF-8
  # DISCOURSE_DEFAULT_LOCALE: en
  UNICORN_WORKERS: 2
  DISCOURSE_DEVELOPER_EMAILS: ''
  DISCOURSE_HOSTNAME: ''
  DISCOURSE_RELATIVE_URL_ROOT: /community

  ## TODO: この Discourse インスタンスが使用するメールサーバー
  DISCOURSE_SMTP_ADDRESS:
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: 
  DISCOURSE_SMTP_PASSWORD: 
  DISCOURSE_SMTP_ENABLE_START_TLS: true
  DISCOURSE_SMTP_OPENSSL_VERIFY_MODE: none
  DISCOURSE_SMTP_AUTHENTICATION: login

  ## この Discourse インスタンスの CDN アドレス(プル用に設定)
  #DISCOURSE_CDN_URL: //discourse-cdn.example.com

## これらのコンテナはステートレスであり、すべてのデータは /shared に保存されます
volumes:
  - volume:
      host: /var/discourse/shared/standalone
      guest: /shared
  - volume:
      host: /var/discourse/shared/standalone/log/var-log
      guest: /var/log

## docker manager プラグインを使用すると、ワンクリックで Discourse をアップグレードできます
## http://discourse.example.com/admin/docker
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - mkdir -p plugins
          - git clone https://github.com/discourse/docker_manager.git
    #          - git clone https://github.com/discourse/discourse-chat-integration.git
    #          - git clone https://github.com/gdpelican/babble.git
    #          - git clone https://github.com/discourse/discourse-solved.git
    #          - git clone https://github.com/discourse/discourse-adplugin.git
    #          - git clone https://github.com/communiteq/discourse-sitemap.git
    #          - git clone https://github.com/discourse/discourse-bbcode-color.git

## 覚えておいてください、これは YAML 構文です。同じ名前のブロックは 1 つしか持てません
run:
    - exec:
        cd: $home
        cmd:
          - rm -fr public/assets
          - sudo -E -u discourse bundle exec rake assets:precompile
          - mkdir -p public/community
          - cd public/community && ln -s ../uploads && ln -s ../backups
    - replace:
       global: true
       filename: /etc/nginx/conf.d/discourse.conf
       from: proxy_pass http://discourse;
       to: |
          rewrite ^/(.*)$ /community/$1 break;
          proxy_pass http://discourse;
    - replace:
       filename: /etc/nginx/conf.d/discourse.conf
       from: etag off;
       to: |
          etag off;
          location /community {
             rewrite ^/community/?(.*)$ /$1;
          }
    - replace:
         filename: /etc/nginx/conf.d/discourse.conf
         from: $proxy_add_x_forwarded_for
         to: $http_fastly_client_ip
         global: true

    - exec: echo "End of custom commands" 

ブラウザ上では以下のようになります:

YML 設定ですべてのプラグインを無効にしましたが、アセットで 404 エラーが発生します。app コンテナ内では、すでに「community」フォルダが作成されています。

何か良い案はありませんか?

I made the below changes to the config but did not help.

run:
    - exec:
        cd: $home
        cmd:
          - mkdir -p public/community
          - cd public/community && ln -s ../uploads && ln -s ../backups
    - replace:
       global: true
       filename: /etc/nginx/conf.d/discourse.conf
       from: proxy_pass http://discourse;
       to: |
          rewrite ^/(.*)$ /forum/$1 break;
          proxy_pass http://discourse;
    - replace:
       filename: /etc/nginx/conf.d/discourse.conf
       from: etag off;
       to: |
          etag off;
          location /community {
             rewrite ^/community/?(.*)$ /$1;
          }
    - replace:
         filename: /etc/nginx/conf.d/discourse.conf
         from: $proxy_add_x_forwarded_for
         to: $http_your_original_ip_header
         global: true

update:

there are 2 folders in /public/community i.e. “backup” and “uploads”. I tried changing the version from tests-passed to stable again but the issue remains the same i.e. no javascript or CSS files and giving 404 error… I also tried to change the permission for the “uploads” folder in community and symlinked assets folder in community but did not help.

Downgrading isn’t possible, if you’re on tests-passed you can’t rebuild on a lower version (beta/stable).

You would need to stay on the current tests-passed release until Stable or Beta catches up.

Subfolder installs are considered an advanced topic and we really can’t support them here because of all the problems which arise. There are pages and pages of topics detailing the types of problems found when installing against a subfolder. In 2019 there’s really no good reason to use a subfolder install, all of the SEO claims have been debunked, and the added complexity really adds nothing of value.

Even on CDCK hosting, subfolder installs are only available to enterprise customers, with an additional fee.

I would suggest reverting to a subdomain, or opening a topic on marketplace to engage with a consultant.

I destroyed the container and then rebuild it with the stable release, the problem is with the assets i.e. CSS or javascript files which are not being found. This error happened probably in the update of May. Is there a way I install the previous versions?

Destroying the container doesn’t help, your database was migrated, and as I’ve already said above there’s no way to migrate back. If you didn’t take a backup prior to upgrade you’re stuck at tests-passed until beta or stable reaches the same level.

If you have a backup from then you might be able to do a new build and put the Verdun you want in the version line.

You might try entering the container and doing a

 rake assets:precompile

My current subfolder solution is with traefik as the reverse proxy. I offer that installation as a service if you’re interested.

現在、私はまず新規インストールを試みています。最初の投稿でもお分かりいただける通り、登録ページも正常に動作していません。assets:precompile を試してみましたが、効果はありません。Discourse Docker の古いバージョンをインストールして試す方法はありませんか?

このフォーラムを数週間だけ使ってから削除するつもりがない限り、絶対に古いバージョンを使うべきではありません。

おそらく、外部 Nginx 設定などで見落とした小さな手順が問題の原因だと思われます。最新バージョンでその原因を特定することをお勧めします。

Serve Discourse from a subfolder (path prefix) instead of a subdomain に従った完全な新規インストールは動作しませんか?

はい、動作していません。そのため、404エラーで止まっています。JavaScriptファイルが読み込まれず、最初の投稿に示されているように404エラーが発生しています。

これは Nginx リバースプロキシの外部設定です。

location /community {
        pagespeed  off;
        rewrite         /(.*) /$1  break;
        proxy_pass      http://127.0.0.1:25654/;
        proxy_read_timeout      90;
        proxy_redirect  http://127.0.0.1:25654/ https://www.domain.com/community;
        proxy_set_header Host $http_host;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

ただし、上記の yml ファイルは Serve Discourse from a subfolder (path prefix) instead of a subdomain のものとは異なっているように見えます。

それは、その設定ファイルが過去に機能しなかったためです。私が現在使用している設定ファイルは、@neilこちらで提案したもので、過去に機能していました。現在、そこにアップロードされた設定ファイルも試しましたが、これも機能しませんでした。

さて、私はちょうど新しいドロプレットを購入し、Serve Discourse from a subfolder (path prefix) instead of a subdomain に従って https://subfolder.muito.ninja/forum にセットアップしました。

私の環境では正常に動作しています。

そのため、あなたのリバースプロキシがそれを壊しているのではないかと心配です…

@john3 さん、サブフォルダへのインストールは骨が折れますね :grinning:

私の設定(左)と yours(右)を比較しました。12 行目をご覧ください。おそらく forum という単語を変更し忘れたのでしょう。次に、22〜29 行目に replace ブロックが追加されています:

最終結果:

外部プロキシ:

location /discuss {

## これは Nginx 用の ProxyPassReverse です
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $remote_addr;

proxy_set_header X-Forwarded-Proto $scheme;

proxy_read_timeout     3600;
proxy_connect_timeout  240;
proxy_set_header Host $host;
proxy_set_header X-RealIP $remote_addr; # ログ記録の目的にとって重要な行

## ここまでが Nginx 用の ProxyPassReverse です

proxy_pass http://192.168.1.2$request_uri;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

リバースプロキシの設定を共有していただけますか?

変更を加えましたが、状況は変わりません。私の設定は以下の通りです。CentOS 7 を使用しており、ストレージドライバは overlay2 です。

Nginx リバースプロキシ:

location /community {
                pagespeed  off;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $remote_addr;

proxy_set_header X-Forwarded-Proto $scheme;

proxy_read_timeout     3600;
proxy_connect_timeout  240;
proxy_set_header Host $host;
proxy_set_header X-RealIP $remote_addr; #当社のログ取得目標にとって重要な行

## ここまでが Nginx の ProxyPassReverse です

proxy_pass http://127.0.0.1:25654$request_uri;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

app.yml

run:
    - exec:
        cd: $home
        cmd:
          - mkdir -p public/community
          - cd public/community && ln -s ../uploads && ln -s ../backups
    - replace:
       global: true
       filename: /etc/nginx/conf.d/discourse.conf
       from: proxy_pass http://discourse;
       to: |
          rewrite ^/(.*)$ /community/$1 break;
          proxy_pass http://discourse;
    - replace:
       filename: /etc/nginx/conf.d/discourse.conf
       from: etag off;
       to: |
          etag off;
          location /community/ {
             rewrite ^/community/?(.*)$ /$1;
          }
    - replace:
       filename: /etc/nginx/conf.d/discourse.conf
       from: etag off;
       to: |
          etag off;
          location /community {
             rewrite ^/community/?(.*)$ /$1;
          }
    - replace:
         filename: /etc/nginx/conf.d/discourse.conf
         from: $proxy_add_x_forwarded_for
         to: $http_fastly_client_ip
         global: true

    - exec: echo "カスタムコマンド終了"

YML 設定の最後の部分、つまり -exec… の部分を教えていただけますか?

これは、リバースプロキシに使用しているソフトウェアによって異なります。

私は Caddy を使用しており、Use Caddy instead of NGINX as your reverse proxy の手順に従っています。

ガイドとの唯一の変更点は、Caddyfile にフォルダーを追加していることです。

subfolder.muito.ninja

proxy /forum unix:/sock/nginx.http.sock {
  transparent
}

なるほど… 私は Digital Ocean の Droplet を使用しており、CentOS 7 と overlay2 ストレージドライバ、Web サーバーには Nginx、SSL には Let’s Encrypt を採用しています。