Recent Changes Breaking Subfolder Setup?

I’m sorry if I’ve misdiagnosed this, but I’ve recently experienced some issues after an upgrade on a subfolder setup that had been working before, so I think there may have been a regression on some fronts in the recent past? In particular, I am self-hosting Discourse using the subfolder setup described here, which was happily working (AFAICT) until recently.

Currently, when logging in using SSO or when switching to/from anonymous mode (and maybe in other situations I’ve not yet found), I am redirected to https://my_machine/discourse_path_stuff , rather than being redirected to https://my_machine/forum/discourse_path_stuff. It’s also the case that when I go to https://my_machine/forum (the right endpoint), my address bar is rewritten to say https://my_machine (with the subfolder removed), though most links seem to resolve to the right places.

Unfortunately, I don’t remember what commit I was running on when things were working, but I’m pretty sure it was under the “2.4.0.beta10” umbrella, and was probably within the last ~10 days. I am currently running on bd49d4af1a.

I apologize if I’m just doing something stupid, and I’m happy to help with tracking down the issue if there are suggestions for where I should be looking.

1 Like

Can you share the site URL ? Are you using our SSO protocol or some OAuth2 / omniauth strategy?

2 Likes

Sure, it’s at https://py.mit.edu/forum (but that’s currently locked off from public viewing). https://py.mit.edu/forum/login demonstrates the problem (though I put another NGINX rule in place specifically to 302 https://py.mit.edu/login back to https://py.mit.edu/forum/login once we started seeing this, which has been a workaround for the SSO part, at least).

We’re using the Discourse SSO protocol, which was definitely working smoothly before. The handshake still seems to happen fine, just redirecting to the wrong place at the end. The "return_sso_url" key in the SSO payload is coming back to our SSO endpoint correctly, though (with /forum).

I also tried a rebuild, but that didn’t seem to fix the issue.

Unfortunately, this may be difficult to debug since I’m not really comfortable giving outside people access, since this instance exists for a class, and I don’t feel comfortable sharing student data with outside parties (even if I trust you personally!). But if it helps, I’m happy to try to replicate this setup on a different server that I could give you access to…

3 Likes

I also see that the link for entering/leaving anonymous mode is using the window.location.reload() to reload the page after sending a request to an endpoint to switch to anonymous mode. So that reload would definitely see the rewritten URL (no longer containing /forum), which would cause this (not sure if it’s a similar story for the SSO problems).

I’ll take a peek at the recent changesets to see if the thing that (I think?) is rewriting window.location is a recent addition.

Also, Discourse.getURL('/login') still gives me the right result (with /forum).

1 Like

The paths reset without subfolder prefix in the address bar of the browser.

Example:
I visit example.com/forum -> after forum loaded, address bar shows example.com
Then I click on “Latest” -> navigates to latest and address bar shows example.com/forum/latest
I hit refresh on browser, website refreshes and address bar shows example.com/latest
When I refresh again while on example.com/latest, there is a 404 error (because my nginx only routes /forum to discourse).

The link preview at bottom left of the browser show up as example.com/latest, example.com/new etc. Refreshing a topic also removes /forum from the url, but then it changes again, back to /forum/t/[…].

I was at version 2.4.0.beta2 previously and don’t remember this issue.

3 Likes

Was this install created following Subfolder support with Docker ? Can you link to it?

7 Likes

Yes, I also tried it on a fresh local install and got the same issue:

app.yml

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

expose:
 - 80:80

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

env:
  LANG: en_US.UTF-8
  UNICORN_WORKERS: 3
  DISCOURSE_RELATIVE_URL_ROOT: /forum
  DISCOURSE_HOSTNAME: localhost
  DISCOURSE_DEVELOPER_EMAILS: yyy

  DISCOURSE_SMTP_ADDRESS: yyy
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: yyy@yyy.yyy
  DISCOURSE_SMTP_PASSWORD: yyy
  DISCOURSE_SMTP_AUTHENTICATION: login

volumes:
  - volume:
      host: /var/discourse/shared/standalone
      guest: /shared
  - volume:
      host: /var/discourse/shared/standalone/log/var-log
      guest: /var/log

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
            - git clone https://github.com/discourse/docker_manager.git

run:
    - exec:
        cd: $home
        cmd:
          - mkdir -p public/forum
          - cd public/forum && 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 /forum {
             rewrite ^/forum/?(.*)$ /$1;
          }
5 Likes

I can reproduce the issue on my subfolder install. We’ll get this fixed.

6 Likes

Great, thanks! Glad to know that I’m not crazy.

From poking around in the recent(ish) commits, though, I couldn’t see an obvious point where this rewrite was happening. Would it be possible to get a pointer to where in the code this was/is happening? (I’m in the process of trying to familiarize myself with the codebase).

1 Like

It would be! I’m just not your guy. I’m just “that guy” on the team that happens to have a local subfolder install. But I’m not an engineer. David should be able to point you in the right direction when he starts working on the issue later this week.

6 Likes

Almost certainly this change which was for this issue. I’m not sure exactly what the issue is, but I’ll be looking into it :eyes:

6 Likes

Turns out it was completely unrelated to that commit. I’ve found the source of the issue, and a fix is in the pipeline:

https://github.com/discourse/discourse/pull/8932

12 Likes

Excellent detective :male_detective:‍♂ work @david :clap:

6 Likes

This is now merged - @hartz and @bokos can you confirm that the issue is resolved after an update?

5 Likes

After a little bit of testing, things do indeed seem to be working again. Thanks, @david !

2 Likes