404 errors (assets) on Subfolder installation

It’s been one month exactly since discourse has been giving me 404 error on assets files (css/js etc) after I did “git pull” and then “rebuild” on approximately May 15th as its was asking me upgrade via command line on the automatic upgrade page.

And then now today after several days, I have tried to reinstall again and it’s still the same even though it’s been days. My app.yml file content is given below.

##
## After making changes to this file, you MUST rebuild for any changes
## to take effect in your live Discourse instance:
##
## /var/discourse/launcher rebuild app
##
## Make sure to obey YAML syntax! You can use this site to help check:
## http://www.yamllint.com/

## this is the all-in-one, standalone Discourse Docker container template

# You may add rate limiting by uncommenting the web.ratelimited template.
# Out of the box it allows 12 reqs a second per ip, and 100 per minute per ip
# This is configurable by amending the params in this file

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: The mailserver this Discourse instance will use
  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

  ## The CDN address for this Discourse instance (configured to pull)
  #DISCOURSE_CDN_URL: //discourse-cdn.example.com

## These containers are stateless, all data is stored in /shared
volumes:
  - volume:
      host: /var/discourse/shared/standalone
      guest: /shared
  - volume:
      host: /var/discourse/shared/standalone/log/var-log
      guest: /var/log

## The docker manager plugin allows you to one-click upgrade 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

## Remember, this is YAML syntax - you can only have one block with a name
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" 

on browser:

I have disabled all the plugins in the YML config, but its 404 error on assets. In the app container, the folder “community” is already created.

Any suggestions?

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, но это не дало никакого эффекта. Есть ли способ попробовать установить более старую версию Docker для Discourse?

Если только вы не планируете использовать этот форум неделю-другую, а затем удалить его, вам действительно, действительно, действительно не стоит этого делать.

Полагаю, вы где-то упустили какой-то мелкий шаг, который и вызывает проблему, скорее всего, в конфигурации внешнего 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;
}

Но файл YAML, который вы привели выше, не похож на тот, что находится по адресу Serve Discourse from a subfolder (path prefix) instead of a subdomain.

Это потому, что тот файл конфигурации раньше не работал, поэтому тот, который я использую сейчас, был рекомендован @neil здесь, и он раньше работал. В настоящее время я также попробовал файл конфигурации, загруженный там, но он тоже не сработал.

Ну, я только что купил новый дроплет и настроил его здесь: https://subfolder.muito.ninja/forum, следуя инструкции Serve Discourse from a subfolder (path prefix) instead of a subdomain

У меня всё работает отлично.

Поэтому, боюсь, ваш обратный прокси что-то ломает…

Привет, @john3, установка в подпапку — это больно :grinning:

Я сравнил свою конфигурацию (слева) и твою (справа), посмотри на строку 12, вероятно, ты забыл изменить слово forum. Далее у меня есть дополнительный блок replace, строки 22–29:

Конец:

Внешний прокси:

location /discuss {

## Это ProxyPassReverse для Nginx
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; #Важная строка для нашей цели логирования

## Конец: это ProxyPassReverse для Nginx

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 reverse proxy:

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; #Важная строка для нашей задачи логирования

## Конец: это ProxyPassReverse для Nginx

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
}

Понятно… Я использую цифровой океанский дроплет с Centos 7 и драйвером хранилища overlay2. Nginx в качестве веб-сервера и SSL от Let’s Encrypt.