Run Discourse in a Subdirectory

(Felix Freiberger) #1

I’m trying to run discourse in a subdirectory. I’ve set up nginx on the server that forwards requests to /discourse/ to a high, firewalled port, and am trying to set up discourse to run on this port.

I have minimally adapted the standalone template to my app.yml, which works fine - but assumes to run in the root directory. After a bit of reading configuration files, I think the needed setting is DISCOURSE_RELATIVE_URL_ROOT: /discourse in the env block.

When setting this entry, rebuilding, and pointing a browser to http://localhost:61001/, I get a Not Found: /, as expected. However, on http://localhost:61001/discourse/, I do get a blank page. Looking at the dev tools, I see that the HTML and CSS were delivered, but all JavaScript files ended up with a 404.

When am I doing wrong? I’m running the current master version, commit 904f795e17.

Contributor Interviews – Felix "fefrei"
(Jeff Atwood) #2

Any ideas @neil ? Running in a subfolder does work and is supported as of 1.3.

(Felix Freiberger) #3

Now, I’m confused even more.
After cleaning the shared directory and re-building from the exact same app.yml (just renamed - I was trying to re-write it), it appears that it is once again serving discourse from / (and http://localhost:61001/discourse/ tells me that this site doesn’t exist or is private).

(Felix Freiberger) #4

Okay, the last thing was me messing up.
The problem of JavaScript not being found persists.

Let me also add that the logs are inconclusive, and fully re-installing Discourse (nuking /var/discourse and all docker containers and images, then re-following the setup instructions) didn’t help.

(Neil Lalonde) #5

We don’t seem to have a howto on this yet… Here’s what you’ll need in the run section of your yml file (using /forum as the relative_url_root):

    - exec: cd $home && sudo -E -u discourse bundle exec rake db:migrate
    - exec:
        cd: $home
          - rm -fr tmp/cache
          - rm -fr public/assets
          - sudo -E -u discourse bundle exec rake assets:precompile
          - mkdir -p public/forum
          - cd public/forum && ln -s ../uploads && ln -s ../backups
          - rm public/uploads
          - rm public/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;

I think that should do it.

(Felix Freiberger) #6

Yes, documenting this seems like a good idea :smile:

In the meantime, I gave up and set up a subdomain for Discourse, so I can’t easily verify that this suffices.

(Neil Lalonde) #7

Glad to hear it. :smile: I haven’t heard a convincing reason for using a subfolder over a subdomain anyway.

(Felix Freiberger) #8

My reason was: The domain I’m working in isn’t mine, and I only control a subdomain. I want to have multiple things there, including a private Discourse for the team. The certificate I have doesn’t cover sub-subdomains.

(Jeff Atwood) #9

That seems fine, what we tend to hear is BECAUSE ARCANE SEO MAGICKS and that’s not what we hear back from Matt Cutts, so…

It wouldn’t really matter if the hosting (putting Discourse on a different server than the rest of your site) didn’t become insanely, orders-of-magnitude-harder with subfolders. But sadly it does.

(Andy Rothfusz) #10

Update: this is now a HOWTO located here: Subfolder support with Docker