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


(Wesley) #47

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?


(Ch Ali Sabir) #48

@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.


(Jeff Atwood) #49

This is not supported and will not work.


(Vikas Dangi) #50

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.


(Jeff Atwood) #51

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


(Jay Patel) #52

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


(Jay Patel) #53

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


(cpradio) #54

That is correct. A rebuild will not lose any data


(Jay Patel) #55

Thank you @cpradio It works like charm :slight_smile:


(Jay Patel) #56

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


(cpradio) #57

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


(Jay Patel) #58

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


(cpradio) #59

Yes, that would be correct.


(Jay Patel) #60

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.


(Eoin Ryan) #61

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?


(Freddie Haddad) #63

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?


(Roxy Xi) #64

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?


#65

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 )


#66

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


(Ultra Noob) #67

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.