# (Superseded) Redirect additional domain(s) to your Discourse instance

**URL:** https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492
**Category:** Self-Hosting
**Tags:** how-to
**Created:** [August 5, 2014, 10:46am UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492 "2014-08-05T10:46:41Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [August 5, 2014, 10:46am UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/1 "2014-08-05T10:46:41Z")

</div>

> ⚠ 2024-04-09 @pfaffman edited this to say that this is no longer necessary, as the current NGINX config in the [standard install](https://meta.discourse.org/t/142537?silent=true) redirects everything to `https://HOSTNAME`. You can test this by entering your IP address and see that it gets redirected. If you want multiple domains pointed to your server, you probably want them to have valid https certificates. To do that, follow instructions at [Set up Let’s Encrypt with multiple domains / redirects](https://meta.discourse.org/t/set-up-let-s-encrypt-with-multiple-domains-redirects/56685).

So you want to redirect domain(s) to your Discourse instance? Great, let’s get started!

In this tutorial we’ll show how to redirect `www.example.com` and `example.com` to `talk.example.com`.

## Update DNS Record

Update the A record for the domain(s) you want to redirect to original domain.

## Edit Configuration FIle

Open configuration file `app.yml`. From console, run these commands:

```plaintext
cd /var/discourse
git pull
nano containers/app.yml

```

Configuration file will open in _nano_ editor. Search for _hooks_ (with Ctrl+W) in the file:

```plaintext
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - mkdir -p plugins
          - git clone https://github.com/discourse/docker_manager.git

```

Add `after_web_config` block to the `hooks` (proper indentation is important):

```plaintext
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - mkdir -p plugins
          - git clone https://github.com/discourse/docker_manager.git
  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/discourse_redirect_1.conf
        contents: |
          server {
            listen 80;
            server_name example.com;
            return 301 $scheme://talk.example.com$request_uri;
          }
    - file:
        path: /etc/nginx/conf.d/discourse_redirect_2.conf
        contents: |
          server {
            listen 80;
            server_name www.example.com;
            return 301 $scheme://talk.example.com$request_uri;
          }

```

You can add as many `file` blocks as you want, depending on number of domain(s) you want to redirect:

```plaintext
    - file:
        path: /etc/nginx/conf.d/discourse_redirect_3.conf
        contents: |
          server {
            listen 80;
            server_name discourse.example.com;
            return 301 $scheme://talk.example.com$request_uri;
          }

```

Modify the file name `discourse_redirect_3` and domain name to which you want to redirect `discourse.example.com` as per your need.

_Note that original domain name `talk.example.com` will remain same in all `file` blocks._

After completing your edits, press Ctrl+O then Enter to save and Ctrl+X to exit.

## Rebuild Container

Run this command:

```plaintext
./launcher rebuild app

```

Congratulations, that’s it! Try visiting `example.com` and `www.example.com`, they both will redirect to `talk.example.com`!

---

<div class="post-metadata">

### Author: ![rubydoob](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rubydoob/32/103165_2.png) [@rubydoob](https://meta.discourse.org/u/rubydoob)
#### Post date: [August 18, 2014, 6:07pm UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/5 "2014-08-18T18:07:20Z")

</div>

Just a tip it is also a good idea to redirect commonly **guessed** urls to your main discourse install

```
e.g. forum{s}.example.com => talk.example.com

```

---

<div class="post-metadata">

### Author: ![flexihack](https://avatars.discourse-cdn.com/v4/letter/f/9dc877/32.png) [@flexihack](https://meta.discourse.org/u/flexihack)
#### Post date: [September 13, 2014, 7:46pm UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/6 "2014-09-13T19:46:58Z")

</div>

What do I change

> [@techAPJ](#):
>
> discourse\_redirect\_3

to? Where can I find the name?

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [September 14, 2014, 6:06am UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/7 "2014-09-14T06:06:59Z")

</div>

You can name the `.conf` file as you desire, but for easy understanding and consistent format, I named them as `discourse_redirect_1.conf`, `discourse_redirect_2.conf`, etc.

[**NOTE** : The number of `.conf` files required will depend on the number of domains you want to redirect. If you want to redirect a single domain (e.g `www.domain.com` to `domain.com`) then you will require a single `.conf` file, which you can also name as `discourse_redirect.conf`.]

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [October 25, 2014, 2:56am UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/11 "2014-10-25T02:56:59Z")

</div>

It is not recommended to put Discourse on the root domain, because cookies set on the root domain carry over to all others, and you might end up with max-length cookie errors if you ever want anything else there.

---

<div class="post-metadata">

### Author: ![Webinsane](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/webinsane/32/160268_2.png) [@Webinsane](https://meta.discourse.org/u/Webinsane)
#### Post date: [October 25, 2014, 6:32am UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/12 "2014-10-25T06:32:23Z")

</div>

Why would I want anything else? 😄

I understand. That is exactly my problem. I can log out at non-www and stay logged in www.

CNAME www [mysite.com](http://mysite.com).

I don’t remember this being explicit requirement during the discourse installation. Anyhow, it should work with the setup above.

---

<div class="post-metadata">

### Author: ![Webinsane](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/webinsane/32/160268_2.png) [@Webinsane](https://meta.discourse.org/u/Webinsane)
#### Post date: [October 29, 2014, 3:25pm UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/13 "2014-10-29T15:25:09Z")

</div>

I pretty much tried everything. Even consulted Digital Ocean guys. It seems if Discourse is installed in root there is no option to redirect www domain to non-www?

---

<div class="post-metadata">

### Author: ![winterbox](https://avatars.discourse-cdn.com/v4/letter/w/6de8d8/32.png) [@winterbox](https://meta.discourse.org/u/winterbox)
#### Post date: [November 11, 2014, 12:24am UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/14 "2014-11-11T00:24:44Z")

</div>

I followed the guide, and did rebuild.

I wanted to my `www.example.com` redirect to `example.com`

After the rebuild, I visited `www.example.com`

and I am seeing this.

![](https://global.discourse-cdn.com/meta/original/3X/8/2/820b6247243f8f75c38b8e4fa89bf8f23eea6a1d.png)

What can I do now?

---

<div class="post-metadata">

### Author: ![winterbox](https://avatars.discourse-cdn.com/v4/letter/w/6de8d8/32.png) [@winterbox](https://meta.discourse.org/u/winterbox)
#### Post date: [November 12, 2014, 12:46am UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/15 "2014-11-12T00:46:44Z")

</div>

I tried with DigitalOcean Droplet, then redirection worked fine. (No further configuration required)

The problem above was not using DigitalOcean Droplet.

I am searching what further configuration is required… ☹

If anyone tell me anything… it will be much appreciated.

---

<div class="post-metadata">

### Author: ![lidel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lidel/32/115991_2.png) [@lidel](https://meta.discourse.org/u/lidel)
#### Post date: [November 13, 2014, 3:19pm UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/16 "2014-11-13T15:19:35Z")

</div>

> [@winterbox](#):
>
> I wanted to my [www.example.com](http://www.example.com) redirect to [example.com](http://example.com)

Hm… if `example.com` works fine, and the only problem you have is default page (_Welcome to Nginx on Debian!_) showing at `www.example.com` you just need to add this short server definition at the beginning of your vhost config file (probably something in `/etc/nginx/sites-enabled/*`):

```nginx
server {
    listen 80;
    server_name www.example.com;
    return 301 http://example.com$request_uri
}

```

It will add permanent (301) HTTP redirect from `www.example.com` to `example.com`.  
Remember to reload nginx afterwards.

---

<div class="post-metadata">

### Author: ![winterbox](https://avatars.discourse-cdn.com/v4/letter/w/6de8d8/32.png) [@winterbox](https://meta.discourse.org/u/winterbox)
#### Post date: [November 13, 2014, 3:40pm UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/17 "2014-11-13T15:40:46Z")

</div>

I edited `/etc/nginx/sites-enabled/default`

with:

```
server {
    listen 80;
    server_name www.example.com;
    return 301 http://example.com$request_uri;
}

```

And did:

```
root@ubuntu:/etc/nginx# sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root@ubuntu:/etc/nginx# sudo service nginx reload
 * Reloading nginx configuration nginx [OK]

```

However I am still watching “Welcome to nginx” message 😅

---

<div class="post-metadata">

### Author: ![lidel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lidel/32/115991_2.png) [@lidel](https://meta.discourse.org/u/lidel)
#### Post date: [November 13, 2014, 3:56pm UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/18 "2014-11-13T15:56:54Z")

</div>

In that case I need to take a look at everything in `/etc/nginx/sites-enabled/*` to give you a meaningful answer.  
If you are okay with it, PM me with configuration files.

---

<div class="post-metadata">

### Author: ![Webinsane](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/webinsane/32/160268_2.png) [@Webinsane](https://meta.discourse.org/u/Webinsane)
#### Post date: [November 13, 2014, 8:05pm UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/19 "2014-11-13T20:05:09Z")

</div>

You can set A record for www

Not the best solution because then you end up with duplicate sites that do not share cookies. That was my fix until I fixed nginx problem.

With your setup everything should work. I have added etc/nginx/sites-enabled/default because it was missing. I redirected opposite from non-www to www.

> ```
> listen 80;
> server_name example.com;
> return 301 http://www.example.com$request_uri;
> 
> ```

With all this beauty still no redirection until I found error: `server_names_hash_bucket_size: 32`

So I went to nginx.conf and increased the default bucket size from 32 to 64. Now everything works.

---

<div class="post-metadata">

### Author: ![winterbox](https://avatars.discourse-cdn.com/v4/letter/w/6de8d8/32.png) [@winterbox](https://meta.discourse.org/u/winterbox)
#### Post date: [November 14, 2014, 1:19am UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/20 "2014-11-14T01:19:38Z")

</div>

I have been already using 2 A records for WWW and Non-WWW to same IP Address.

I had duplicate sites as you said.

But this “Welcome to Nginx” message problem started after I did this How-to Guide.

So I have lost my one dupilcate site as I said above, but the other one is working.

ps. I think I have no error in `app.yml`, but I will check one more time.

---

<div class="post-metadata">

### Author: ![winterbox](https://avatars.discourse-cdn.com/v4/letter/w/6de8d8/32.png) [@winterbox](https://meta.discourse.org/u/winterbox)
#### Post date: [November 14, 2014, 6:04am UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/21 "2014-11-14T06:04:00Z")

</div>

Now… it is time to confess.

After 3 days of agony, I finally solved the problem.

I missed `;`

I thought I was so sure about app.yml file… because I checked it again and again. (and didn’t realize that every time)

Anyway… I just found it.

Now everything is working well… 😢

I am sorry to make you guys confused… this How-to guide is perfect.

---

<div class="post-metadata">

### Author: ![Webinsane](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/webinsane/32/160268_2.png) [@Webinsane](https://meta.discourse.org/u/Webinsane)
#### Post date: [November 14, 2014, 5:27pm UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/22 "2014-11-14T17:27:44Z")

</div>

Use [http://www.yamllint.com/](http://www.yamllint.com/) to validate your yml files.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [November 14, 2014, 8:01pm UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/23 "2014-11-14T20:01:18Z")

</div>

It was valid YAML. It was missing a ; in the command. We already validate YAML as part of the bootstrap.

---

<div class="post-metadata">

### Author: ![Webinsane](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/webinsane/32/160268_2.png) [@Webinsane](https://meta.discourse.org/u/Webinsane)
#### Post date: [November 14, 2014, 8:32pm UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/24 "2014-11-14T20:32:41Z")

</div>

Interestingly I remember missing ; in my translation files and yamlint helped.

---

<div class="post-metadata">

### Author: ![vodwood](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vodwood/32/37517_2.png) [@vodwood](https://meta.discourse.org/u/vodwood)
#### Post date: [November 20, 2014, 10:42am UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/25 "2014-11-20T10:42:46Z")

</div>

Sorry, but after doing this should I point only my [domain.com](http://domain.com) to droplet IP with an A record in order for this to work? Or should I make 3 A records (all pointing to the same IP) for [talk.domain.com](http://talk.domain.com), [domain.com](http://domain.com) and [www.domain.com](http://www.domain.com)? Or perhaps 2 A records and 1 CNAME (for www to non-www redirect)?

---

<div class="post-metadata">

### Author: ![winterbox](https://avatars.discourse-cdn.com/v4/letter/w/6de8d8/32.png) [@winterbox](https://meta.discourse.org/u/winterbox)
#### Post date: [November 20, 2014, 11:04am UTC](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492/26 "2014-11-20T11:04:09Z")

</div>

All A records(www/talk/non-www) to the same IP. Then do above configuration in your app.yml. And this will let you redirect. That’s how I did! I didn’t do anything about Cname.

[Next page](https://meta.discourse.org/t/superseded-redirect-additional-domain-s-to-your-discourse-instance/18492.md?page=2)
