How to run discourse on subdirectory of external domain?

Subfolder installs are much more complicated and very fragile.

The point is that there’s zero benefit running under the same FQDN and significantly more risk and cost.

3 Likes

That’s what you believe. But there is no evidence that a subdomain helps boost the bare domain at all.

And even cloudflare recommends running everything in the same domain.

Then why, pray tell, is their discourse community on a subdomain?

4 Likes

Because anything with cloudflare in the domain will rank well. And their forum is enormous

If that’s what you believe, move along. There is nothing for you here. Go elsewhere, go somewhere that people believe the same things you do.

7 Likes

I could link much more links, with data behind them if I wasn’t limited to 2 links. And except for Cloudflare, which is massive and don’t need to focus on SEO all websites on the first page for this search use subdirectories

It won’t be hard to find other places where people believe the same thing since this seems to be consensus on the SEO community.

But sure, if you have ANY evidence that a subdomain helps rank the root domain please enlighten the internet :slight_smile:

Direct from Matt Cutts. Your SEO “experts” are selling you snake oil.

Through the years some of the worst, least competent people I’ve ever seen on a team are the “SEO experts”. They are uniformly a disgrace and an embarrassment to the industry.

7 Likes

True! Tons better to do something that most everyone agrees won’t help web rankings but will likely result in your site being down unexpectedly with no clear means to fix it.

6 Likes

Anyone have tried to do this with cloudflare?

As we’ve already explained in your other topic, what you’re asking to do can’t be supported here.

You will either need an Enterprise plan with Cloudflare, or to create custom workers. Either way you should be talking to Cloudflare.

4 Likes

As stated, the answer that I gave earlier, is all you’ll get here.

What I didn’t make clear enough is that it’s a fool’s errand.

For a frame of reference, I’d charge you on the order of $1000 and provide no promise that it would work for for more than a week after I set it up. (or I might charge $500 with no promise that I could figure it out at all.

And you’d need the cloudflare enterprise plan.

If you’re interested, post in #marketplace and include a budget and that you are willing to pay for cloudflare enterprise and understand that it is likely impossible.

2 Likes

I think I’m 80% done in implementing this. I installed discourse on a subdomain as “normal” install.

Then I created a cloudflare worker proxying /blog to my subdomain. It works but chrome refuses to load some stuff because of CSP policy.

Any ideas to go around this anyone? I’ll share my workers code when it’s 100%.

You can go to UltraLuz Blog - Lampadas led to check what is happening.

My idea is that after I fix this, I’ll just use robots.txt to block google from indexing my subdomain, so it only sees and indexes /blog while I can still access the subdomain just fine if needed

2 Likes

This is never going to work really well with a “normal” install, you really should follow the subfolder install procedure. It will fix your CSP issues and many more. Apart from that, I think you’re almost there.

6 Likes

What I should set DISCOURSE_HOSTNAME when using DISCOURSE_RELATIVE_URL_ROOT ? The relative root will be blog for me right?

How does this change stuff related to SSL? This is my env section of yml

env:
  LANG: en_US.UTF-8
  DISCOURSE_RELATIVE_URL_ROOT: /forum

  VIRTUAL_HOST: forum.ultraluz.com.br
  VIRTUAL_PORT: 80
  LETSENCRYPT_HOST: forum.ultraluz.com.br
  LETSENCRYPT_EMAIL: redacted@email.com

  DISCOURSE_HOSTNAME: forum.ultraluz.com.br
  DISCOURSE_DEVELOPER_EMAILS: 'redacted@email.com'

  DISCOURSE_SMTP_ADDRESS: smtp.sendgrid.net
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: apikey
  DISCOURSE_SMTP_PASSWORD: "password"
  DISCOURSE_SMTP_ENABLE_START_TLS: true
  SSL_POLICY: Mozilla-Modern  

The letsencrypt and virtual host stuff is for my nginx docker (jwilder/nginx-proxy) that handles the proxying and ssl creation for me based on that variables…

Also had this but I think it will be fully replaced by the code there?

run:
  - replace:
      filename: /etc/nginx/conf.d/discourse.conf
      from: "types {"
      to: |
        set_real_ip_from 172.18.0.0/24;
        real_ip_header X-Forwarded-For;
        real_ip_recursive on;
        types {
1 Like

Yes, /blog including the slash.

No, just ultraluz.com.br.

I guess you should leave the LetsEncrypt part as it is.

4 Likes

It didn’t work this way. I guess it’s because the worker needs a domain to fetch stuff, and since the root domain is on a different IP.

I’m basically telling the worker "when someone goes to /blog fetch this from rootdomain/blog" this of course just displays my current wordpress 404 error page.

I think because of the whole same domain, multiple IPs/servers things a subdomain is needed to load the discourse assets. But it’s late now and I need to sleep.

But I think the easiest way to achieve this will be to just fix the CSP errors with usual subdomain install.

1 Like

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