# Forcing access to Discourse via domain name only

**URL:** https://meta.discourse.org/t/forcing-access-to-discourse-via-domain-name-only/70574
**Category:** Self-hosting
**Created:** [September 22, 2017, 1:39pm UTC](https://meta.discourse.org/t/forcing-access-to-discourse-via-domain-name-only/70574 "2017-09-22T13:39:32Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Carlo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/carlo/32/79036_2.png) [@Carlo](https://meta.discourse.org/u/Carlo)
#### Post date: [September 22, 2017, 1:39pm UTC](https://meta.discourse.org/t/forcing-access-to-discourse-via-domain-name-only/70574/1 "2017-09-22T13:39:33Z")

</div>

Hi everyone. So I have setup Discourse and configure Cloudflare and SSL connection.  
So far so good. Now I see my website is accessible via the domain name and the default ip, which I do not want.

When I use a CMS such as Wordpress or Modx ( on apache ), I normally configure the ht.access to do the trick. But Discourse is not on Apache…

Is there a way to do that with Nginx ? I am not even sure that Discourse uses it.

Anyway that is the code I would be using:

```
# Tells the browser to always force SSL.
# Do not use this line if there is a chance you will turn off SSL

add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";

if ($scheme != "https") {
	rewrite ^ https://discourse.mydomain.com$request_uri permanent;
}
if ($host != "discourse.mydomain.com") {
	rewrite ^ https://discourse.mydomain.com$request_uri permanent;
}

```

Any suggestions ?

Thanks

---

<div class="post-metadata">

### Author: ![Carlo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/carlo/32/79036_2.png) [@Carlo](https://meta.discourse.org/u/Carlo)
#### Post date: [October 5, 2017, 8:39am UTC](https://meta.discourse.org/t/forcing-access-to-discourse-via-domain-name-only/70574/2 "2017-10-05T08:39:47Z")

</div>

Still haven’t find a simple way to do it.

If anyone has a solution I’d be grateful 🙂

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [October 5, 2017, 1:25pm UTC](https://meta.discourse.org/t/forcing-access-to-discourse-via-domain-name-only/70574/3 "2017-10-05T13:25:23Z")

</div>

It sounds like your question is something like:

host:port at 123.123.123.123:8080  
domain `example.com` maps to host:port  
you don’t want requests for host:port to work, but only requests for the domain that are mapped to the host:port

But that doesn’t make sense to me and the code example you posted isn’t about that so I am confused.

What instructions did you follow for your install and is this a domain name, host IP, or port problem?

---

<div class="post-metadata">

### Author: ![Carlo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/carlo/32/79036_2.png) [@Carlo](https://meta.discourse.org/u/Carlo)
#### Post date: [October 5, 2017, 2:05pm UTC](https://meta.discourse.org/t/forcing-access-to-discourse-via-domain-name-only/70574/4 "2017-10-05T14:05:57Z")

</div>

Really sorry I didn’t make myself clear.

Let say my website is hosted on the ip: 123.123.123.123  
And this is my domain name: [forum.example.com](http://forum.example.com)

Right now, visitors can browse the forum by accessing the ip 123.123.123.123

**What I want is:**

When someone goes to the ip, it will be redirect to [forum.example.com](http://forum.example.com)

The issue is that I am not able to locate ngnix default file.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [October 5, 2017, 2:21pm UTC](https://meta.discourse.org/t/forcing-access-to-discourse-via-domain-name-only/70574/5 "2017-10-05T14:21:12Z")

</div>

Enable https. Run disourse-setup again and give your email address for the let’s encrypt question.
