How to run discourse on subdirectory of external domain?

So I have been able to fix this with nginx. I gave up on workers as I don’t know much about them…

The idea is that my root domain will point to a server I control, and I’ll let nginx merge the two platforms together.

server
{
    listen 80;
    server_name test.ultraluz.com.br;

    location /blog {
        proxy_set_header Host forum.ultraluz.com.br;
        proxy_pass https://forum.ultraluz.com.br/;
        proxy_redirect https://forum.ultraluz.com.br/ http://test.ultraluz.com.br/blog;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

       location /stylesheets {
        proxy_set_header Host forum.ultraluz.com.br;
        proxy_pass https://forum.ultraluz.com.br/stylesheets;
        proxy_redirect https://forum.ultraluz.com.br/ http://test.ultraluz.com.br/blog;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    
       location /assets {
        proxy_set_header Host forum.ultraluz.com.br;
        proxy_pass https://forum.ultraluz.com.br/assets;
        proxy_redirect https://forum.ultraluz.com.br/ http://test.ultraluz.com.br/blog;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

        location /svg-sprite {
        proxy_set_header Host forum.ultraluz.com.br;
        proxy_pass https://forum.ultraluz.com.br/svg-sprite;
        proxy_redirect https://forum.ultraluz.com.br/ http://test.ultraluz.com.br/blog;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

        location /404-body {
        proxy_set_header Host forum.ultraluz.com.br;
        proxy_pass https://forum.ultraluz.com.br/404-body;
        proxy_redirect https://forum.ultraluz.com.br/ http://test.ultraluz.com.br/blog;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

        location /message-bus {
        proxy_set_header Host forum.ultraluz.com.br;
        proxy_pass https://forum.ultraluz.com.br/message-bus;
        proxy_redirect https://forum.ultraluz.com.br/ http://test.ultraluz.com.br/blog;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

               location /latest.json {
        proxy_set_header Host forum.ultraluz.com.br;
        proxy_pass https://forum.ultraluz.com.br/latest.json;
        proxy_redirect https://forum.ultraluz.com.br/ http://test.ultraluz.com.br/blog;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

                       location /javascripts {
        proxy_set_header Host forum.ultraluz.com.br;
        proxy_pass https://forum.ultraluz.com.br/javascripts;
        proxy_redirect https://forum.ultraluz.com.br/ http://test.ultraluz.com.br/blog;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

                            location /logs {
        proxy_set_header Host forum.ultraluz.com.br;
        proxy_pass https://forum.ultraluz.com.br/logs;
        proxy_redirect https://forum.ultraluz.com.br/ http://test.ultraluz.com.br/blog;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

                                  location /u {
        proxy_set_header Host forum.ultraluz.com.br;
        proxy_pass https://forum.ultraluz.com.br/u;
        proxy_redirect https://forum.ultraluz.com.br/ http://test.ultraluz.com.br/blog;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

This works, but I only have one issue. When people go to /blog they see the discourse 404 page doesn’t exist instead of the homepage? I’m not sure what could be causing this?

1 Like

You are going on a wrong path by trying to list every single route in your nginx file. That will never work.

First install discourse in a server following Subfolder support with Docker. Use an internal domain for this, so the configuration works. You will also need to remove ssl templates from app.yml.

Then, in the server where you control the actual domain, add a single location block with the subfolder and use the necessary proxy directives to send traffic to the server where discourse is located.

5 Likes

I have tried following that guide…

 DISCOURSE_RELATIVE_URL_ROOT: /blog
 DISCOURSE_HOSTNAME: forum.ultraluz.com.br

So I expected to be able to access the forum going to forum.ultraluz.com.br/blog but I only get connection refused so that’s what I think it’s confusing on that guide.

Is not clear what URL we should use to be able to fetch assets…

1 Like

If you followed the Subfolder support with Docker guide and at the end you can’t access the forum, you messed up badly at some step.

Destroy the server and try again.

3 Likes