# Block Direct Connections

**URL:** https://meta.discourse.org/t/block-direct-connections/22450
**Category:** Self-hosting
**Created:** [November 23, 2014, 7:48pm UTC](https://meta.discourse.org/t/block-direct-connections/22450 "2014-11-23T19:48:10Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![balintant](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/balintant/32/115249_2.png) [@balintant](https://meta.discourse.org/u/balintant)
#### Post date: [November 23, 2014, 7:48pm UTC](https://meta.discourse.org/t/block-direct-connections/22450/1 "2014-11-23T19:48:10Z")

</div>

How can I block direct connections to Discourse and force people to use my domain instead of the ip:port version?

It is important because my server would work like this:

> Varnish → Nginx → Discourse.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [November 23, 2014, 7:51pm UTC](https://meta.discourse.org/t/block-direct-connections/22450/2 "2014-11-23T19:51:05Z")

</div>

use a private ip for nginx and discourse.

---

<div class="post-metadata">

### Author: ![balintant](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/balintant/32/115249_2.png) [@balintant](https://meta.discourse.org/u/balintant)
#### Post date: [November 23, 2014, 10:01pm UTC](https://meta.discourse.org/t/block-direct-connections/22450/3 "2014-11-23T22:01:29Z")

</div>

Yeah, I see and I’ve set Nginx to listen to 127.0.0.1:8080, but how can I set Discourse to use only 127.0.0.1:8020?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [November 23, 2014, 11:59pm UTC](https://meta.discourse.org/t/block-direct-connections/22450/4 "2014-11-23T23:59:34Z")

</div>

Your container is in a sandbox, you choose what to export out of it.

---

<div class="post-metadata">

### Author: ![balintant](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/balintant/32/115249_2.png) [@balintant](https://meta.discourse.org/u/balintant)
#### Post date: [November 24, 2014, 7:58am UTC](https://meta.discourse.org/t/block-direct-connections/22450/5 "2014-11-24T07:58:56Z")

</div>

I see! People wrote everywhere that I want to use `iptables`, but there was no formula which would work for me.

The solution is to write the ip (`127.0.0.1`) before the port:

```plaintext
expose:
  - "127.0.0.1:8020:80"

```

Thanks for your help!
