子文件夹安装中的 404 错误(资源)

自从 5 月 15 日左右,Discourse 在自动升级页面提示我通过命令行升级后,我执行了 git pull 然后 rebuild,此后整整一个月,访问资源文件(如 css/js 等)时一直返回 404 错误。

今天,在尝试了几天后,我再次尝试重新安装,但问题依旧存在,尽管已经过去了数天。我的 app.yml 文件内容如下:

##
## 修改此文件后,您必须执行 rebuild 才能使更改在您的 Discourse 生产实例中生效:
##
## /var/discourse/launcher rebuild app
##
## 请确保遵守 YAML 语法!您可以使用以下网站帮助检查:
## http://www.yamllint.com/

## 这是 Discourse 的独立 Docker 容器模板

# 您可以通过取消注释 web.ratelimited 模板来添加速率限制。
# 默认情况下,它允许每个 IP 每秒 12 个请求,每分钟 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 语法——您只能拥有一个带名称的块
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" 

在浏览器中:

![17%20PM|690x341](upload://sB8QorcbmiJt46kEj7kcXZ0aIbt.png) 

我已在 YML 配置中禁用了所有插件,但资源文件仍然返回 404 错误。在应用容器中,"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 在此处(https://meta.discourse.org/t/blank-page-after-installing-discourse-on-subfolder/96112/5)推荐的配置,它过去是有效的。目前,我也尝试了那里上传的配置文件,但同样无法工作。

好吧,我刚刚购买了一个全新的 Droplet,并按照 Serve Discourse from a subfolder (path prefix) instead of a subdomain 的说明在此处设置:https://subfolder.muito.ninja/forum。

对我来说运行正常。

所以我担心是你的反向代理导致了问题……

你好 @john3,子文件夹安装确实很让人头疼 :grinning:

我对比了我的配置(左)和你的配置(右),请看一下第 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
}

明白了……我正在使用 DigitalOcean 的 Droplet 服务器,运行 CentOS 7,存储驱动为 overlay2。Web 服务器是 Nginx,SSL 证书由 Let’s Encrypt 提供。