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 it’s saying that there’s a redirect on the! Not sure what I’m doing wrong, config is below:

    - 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;
            return 301 $scheme://$request_uri;
    - file:
        path: /etc/nginx/conf.d/c_redirect.conf
        contents: |
          server {
            listen 80;
            return 301 $scheme://$request_uri;

Any ideas?


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:
Now, some categories/topics in this instance can belong to a domain say
whereas some categories/topics in this instance can belong to another domain say When I pass URL to, it should only display those categories/topics which belong to

How can I achieve that?

In Joomla, it is possible through a plugin like:

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 to, 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.


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


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.


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 ?

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.

I plan to use this approach to have 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 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 instead of

I’m trying to map to

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


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





That’s all.

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