Redirect single/multiple domain(s) to your Discourse instance

I am experiencing some odd behaviour, with one file block everything works perfectly. When I add the second file block (copy-paste, edit server_name) and then rebuild I get a “Too many redirects” error on all domains. If I remove all but 1 file block, everything is fine again. If I run curl -vso dev/null www.mydomain.com it’s saying that there’s a redirect on the www.mydomain.com! Not sure what I’m doing wrong, config is below:

  after_web_config:
    - replace:
        filename: /etc/nginx/nginx.conf
        from: /sendfile.+on;/
        to: |
          server_names_hash_bucket_size 64;
          sendfile on;
    - file:
        path: /etc/nginx/conf.d/www_redirect.conf
        contents: |
          server {
            listen 80;
            server_name mydomain.com;
            return 301 $scheme://www.mydomain.com$request_uri;
          }
    - file:
        path: /etc/nginx/conf.d/c_redirect.conf
        contents: |
          server {
            listen 80;
            server_name community.mydomain.com;
            return 301 $scheme://www.mydomain.com$request_uri;
          }

Any ideas?

@techAPJ

My use case is something like this:

  1. I want to host a single instance of Discourse which should serve against multiple domains.
  2. This single instance will have categories/topics associated with multiple domains.
  3. When the instance is requested from a domain, the discourse must return only those categories/topics which belong to that domain.

Example: Suppose I have a single instance of discourse hosted as: mydiscouseinstance.com/forums
Now, some categories/topics in this instance can belong to a domain say mydomainone.com/forums
whereas some categories/topics in this instance can belong to another domain say mydomaintwo.com/forums. When I pass URL mydomainone.com/forums to mydiscouseinstance.com/forums, it should only display those categories/topics which belong to mydomainone.com.

How can I achieve that?

In Joomla, it is possible through a plugin like: http://extensions.joomla.org/extension/virtual-domains

Can we do something like that in Discourse too? Thanks for any possible help.

This is not supported and will not work.

I have done all coding work to my website, but have little confusion of updating DNS record. I am redirecting from example.com to www.example.com, so what I have to update in A record.

A record should be for www in that case, sounds correct, then redirect “naked” domain to www.

3 Likes

without following above guide directly changed nginx.conf? i just want only www website on root domain.

for already running discourse just changing app.yml and rebuild will work without loosing data?

That is correct. A rebuild will not lose any data

4 Likes

Thank you @cpradio It works like charm :slight_smile:

do listen port needs to be 443 in hooks or both ? i have redirect to non-www to www with www A record set.

Thanks,
Jay

non-www to www has nothing to do with port 443, port 443 is for SSL.

so if lets encrypt is on listen should be 443 right ?
Thanks

Yes, that would be correct.

I did turned on https first then did redirect from non-www to www but its keep redirecting and end up not loading up discourse.
Thanks.

I plan to use this approach to have chat.example.com as the permanent URL to our site; even if the real URL changes over time (e.g if we move to Discourse hosting etc).

Am I correct to think that mobile Discourse app users who have configured the app with chat.example.com will not be affected by any hosting change; once the steps above are followed during the hosting change window?

These instructions aren’t working for me. Is it because the root domain in the Discourse settings is sunrisepoint.org instead of www.sunrisepoint.org?

I’m trying to map sunrisepoint.org to www.sunrisepoint.org.

Also, if I have https enabled, do the instructions need to be tweaked?

hi.

we are getting several 404 not found errors in our console due to changes in category names. can we redirect those addresses to an existing address using this tutorial?

really interested in this…any new development ? also if I’m using a CDN, I can’t know my server IP right? Or should I use me A record IP even if it’s not public knowledge ( cloudflare is proxying it, so it’s hidden )

What about redirecting https www to non www? Can’t find a portable way to this with the docker

An easy way -

  1. Go to Cloudflare

  2. Add your domain

  3. Update Cloudflare nameservers

  4. At Cloudflare DNS Page, point IP address to your host. Turn on Cloudflare proxy.
    A - old.tld - hosting IP
    CNAME - www - old.tld

  5. Go to Crypto menu > SSL mode, set Flexible

  6. Go to page rule, create a new forwarder

From

*old.tld/*

To

https://new.tld/$2

That’s all.

Now all request from http/https/http-www/https-www of old.tld will goes to https://new.tld domain.

2 Likes