# How to deny request from unauthorized domain pointing to my IP address?

**URL:** https://meta.discourse.org/t/how-to-deny-request-from-unauthorized-domain-pointing-to-my-ip-address/89970
**Category:** Support
**Created:** [June 15, 2018, 12:44pm UTC](https://meta.discourse.org/t/how-to-deny-request-from-unauthorized-domain-pointing-to-my-ip-address/89970 "2018-06-15T12:44:39Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Gulshan\_Kumar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gulshan_kumar/32/119562_2.png) [@Gulshan\_Kumar](https://meta.discourse.org/u/Gulshan_Kumar)
#### Post date: [June 15, 2018, 12:44pm UTC](https://meta.discourse.org/t/how-to-deny-request-from-unauthorized-domain-pointing-to-my-ip-address/89970/1 "2018-06-15T12:44:39Z")

</div>

Any XYZ domain which points to my Digital Ocean droplet IP, it redirects to my forum. This way it has created a lot of uknown 404 logs and affecting link profile.

I am thinking to add a rule like this

```
location / {
  if ($server_name !~ "^forum\.)?example\.com$"){
    return 403;
  }
}

```

which mean deny request from unauthorized domain

Please guide me how can I add?

Thanks & Regards,  
Gulshan

---

<div class="post-metadata">

### Author: ![Cameron\_D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cameron_d/32/97535_2.png) [@Cameron\_D](https://meta.discourse.org/u/Cameron_D)
#### Post date: [June 15, 2018, 1:02pm UTC](https://meta.discourse.org/t/how-to-deny-request-from-unauthorized-domain-pointing-to-my-ip-address/89970/2 "2018-06-15T13:02:50Z")

</div>

[Last time this was brought up](https://meta.discourse.org/t/my-forum-is-opened-with-another-link/70572) the easiest solution was to enable SSL, that will cause the wrong domains to either redirect to the correct one, or show an SSL error:

> [@Set up HTTPS support with Let's Encrypt](https://meta.discourse.org/t/setting-up-lets-encrypt/40709):
>
> bookmark This is a guide for enabling HTTPS on an existing Discourse installation using Let’s Encrypt. It assumes prior installation without HTTPS enabled. person_raising_hand Required user level: System Administrator exclamation This guide is only for existing installs where HTTPS is not enabled. Following the [official setup guide](https://github.com/discourse/discourse/blob/main/docs/INSTALL-cloud.md) automatically enables HTTPS by default. So you’d like to add https to your Discourse absolutely free, courtesy of our friends at [Let’s Encrypt?](https://letsencrypt.org/)bell I…

If thats _not_ an option you can use a pups template to add that 403 block into the Discourse nginx config.

---

<div class="post-metadata">

### Author: ![Gulshan\_Kumar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gulshan_kumar/32/119562_2.png) [@Gulshan\_Kumar](https://meta.discourse.org/u/Gulshan_Kumar)
#### Post date: [June 15, 2018, 1:04pm UTC](https://meta.discourse.org/t/how-to-deny-request-from-unauthorized-domain-pointing-to-my-ip-address/89970/3 "2018-06-15T13:04:06Z")

</div>

I am already using Let’s Encrypt. The issue is what XYZ domain point it simply redirect 301 to my forum.

---

<div class="post-metadata">

### Author: ![Cameron\_D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cameron_d/32/97535_2.png) [@Cameron\_D](https://meta.discourse.org/u/Cameron_D)
#### Post date: [June 15, 2018, 1:10pm UTC](https://meta.discourse.org/t/how-to-deny-request-from-unauthorized-domain-pointing-to-my-ip-address/89970/4 "2018-06-15T13:10:51Z")

</div>

Then adding it to the Discourse nginx config would be the next easiest thing. Using a new pups template would be the best way, to save you needing to re-apply the change every rebuild.

You could try… Make a new file at `/var/discourse/templates/web.403.yml`, with the following contents:

```yml
run:
  - replace:
     filename: "/etc/nginx/conf.d/discourse.conf"
     from: /location / \{/
     to: |
       location / {
         if ($server_name !~ "^forum\.)?example\.com$"){
           return 403;
         }

```

Then edit `/var/discourse/containers/app.yml` and at the bottom of the `templates` section add a new line:

```yml
  - "templates/web.403.yml"

```

And then try and run a `./launcher rebuild app`, see how that goes.

---

<div class="post-metadata">

### Author: ![Gulshan\_Kumar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gulshan_kumar/32/119562_2.png) [@Gulshan\_Kumar](https://meta.discourse.org/u/Gulshan_Kumar)
#### Post date: [June 15, 2018, 1:12pm UTC](https://meta.discourse.org/t/how-to-deny-request-from-unauthorized-domain-pointing-to-my-ip-address/89970/5 "2018-06-15T13:12:30Z")

</div>

Thanks, I will try it in the mid night (less traffic time) and update here what happens.

---

<div class="post-metadata">

### Author: ![Cameron\_D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cameron_d/32/97535_2.png) [@Cameron\_D](https://meta.discourse.org/u/Cameron_D)
#### Post date: [June 15, 2018, 1:16pm UTC](https://meta.discourse.org/t/how-to-deny-request-from-unauthorized-domain-pointing-to-my-ip-address/89970/6 "2018-06-15T13:16:42Z")

</div>

I should add…  
If you want to test that config you can use `./launcher enter app` to get a terminal up in the container, then edit `/etc/nginx/conf.d/discourse.conf` there (`vi` should be installed, or install something more familiar), and you can run `service nginx reload` to apply the config change.

If that all runs well, then my above post will make the change more permenant (by automatically making the change to the file every rebuild)

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [December 27, 2020, 12:21am UTC](https://meta.discourse.org/t/how-to-deny-request-from-unauthorized-domain-pointing-to-my-ip-address/89970/7 "2020-12-27T00:21:37Z")

</div>


