# התקנת Discourse על אינטרנט ביתי באמצעות Cloudflare Tunnel

**URL:** https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297
**Category:** Sysadmins
**Tags:** arm, how-to, raspberry-pi, install
**Created:** [7 בדצמבר,‏ 2021,‏ 2:02pm UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297 "2021-12-07T14:02:07Z")
**Posts on this page:** 20
**Page:** 3

<div class="post-metadata">

### Author: ![shyguy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/shyguy/32/295079_2.png) [@shyguy](https://meta.discourse.org/u/shyguy)
#### Post date: [5 באפריל,‏ 2023,‏ 10:42pm UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/42 "2023-04-05T22:42:49Z")

</div>

yo @Falco, is the real\_ip (provided by cf as `CF-Connecting-IP` header) coming through for you in nginx logs? it’s not for me. i just see `cloudflared`’s ip.

i think one or both of these things need to be done (will follow up after investigation):

- add a `set_real_ip_from` config line to nginx for `cloudflared`’s ip. if that turns out to be the problem, then i would guess none of the other `set_real_ip_from` lines (provided by `templates/cloudflare.template.yml`) are needed for argotunnel users. and in this case, maybe a separate argotunnel template should be added to the docker repo that pulls your `cloudflared` ip from an env var or something in your main `app.yml`.
- ~~fix the `log_format`. i think this is probably not the issue, though.~~ confirmed unneeded

edit:

here’s what i’m doing to make it work:

don’t use the cloudflare template. there’s no point.  
instead, merge this into your `app.yml`:

```yaml
hooks:
  after_web_config:
    - file:
        path: /etc/nginx/conf.d/cloudflare_tunnel_real_ip.conf
        contents: |
          # restore original visitor IPs (ngx_http_realip_module)
          set_real_ip_from 10.100.20.200/32; # your cloudflared/argotunnel IP range
          real_ip_header CF-Connecting-IP;

```

that automatically ends up in the nginx `http` context btw which is appropriate.

PS: imo, for cleanliness, the cloudflare template should also generate its nginx config into a separate file instead of using `sed -i` to add it to `/etc/nginx/conf.d/discourse.conf`.

---

<div class="post-metadata">

### Author: ![syandriz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/syandriz/32/274337_2.png) [@syandriz](https://meta.discourse.org/u/syandriz)
#### Post date: [5 באפריל,‏ 2023,‏ 10:45pm UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/43 "2023-04-05T22:45:26Z")

</div>

yes @shyguy i follow the step mr @Falco  
yes i on tunnel, before i get some ddos protection from cloudflare, ddos give my server get high on cpu, on access log 20mb and i see just my docker ip, i challange the visitor on url path / to protect server but expired cache give discoure error

---

<div class="post-metadata">

### Author: ![syandriz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/syandriz/32/274337_2.png) [@syandriz](https://meta.discourse.org/u/syandriz)
#### Post date: [5 באפריל,‏ 2023,‏ 11:00pm UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/44 "2023-04-05T23:00:48Z")

</div>

![Screenshot 2023-04-06 at 6.56.36 AM](https://global.discourse-cdn.com/meta/original/4X/f/0/7/f07e180357f81dc4b0774e59a02b9b50b0dccc88.png)  
 ![Screenshot 2023-04-06 at 6.56.19 AM](https://global.discourse-cdn.com/meta/original/4X/1/8/0/180816833408608453b08f690b032ae47bcd9138.jpeg)  
 ![Screenshot 2023-04-06 at 7.12.20 AM](https://global.discourse-cdn.com/meta/original/4X/c/0/d/c0d26256c3a7fbe25f7862ad2f356a7f7c45b200.png)

i got same like falco website if got ddos, and get higher on cpu

---

<div class="post-metadata">

### Author: ![kuydiyadri](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuydiyadri/32/305813_2.png) [@kuydiyadri](https://meta.discourse.org/u/kuydiyadri)
#### Post date: [7 במאי,‏ 2023,‏ 8:18am UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/45 "2023-05-07T08:18:20Z")

</div>

> [@shyguy](#):
>
> `10.100.20.200/32; # your cloudflared/argotunnel IP range`

@shyguy where can i get this ip range, sorry for asking

> [@shyguy](#):
>
> PS: imo, for cleanliness, the cloudflare template should also generate its nginx config into a separate file instead of using `sed -i` to add it to `/etc/nginx/conf.d/discourse.conf`.

how about this..? i must use this command inside or outside container?

---

<div class="post-metadata">

### Author: ![shyguy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/shyguy/32/295079_2.png) [@shyguy](https://meta.discourse.org/u/shyguy)
#### Post date: [7 במאי,‏ 2023,‏ 4:35pm UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/46 "2023-05-07T16:35:28Z")

</div>

in case it wasn’t clear, my post there was just about fixing nginx logging.

if you don’t fix it, all of the requests in your nginx logs will look like they’re coming from one ip (your cloudflared) instead of having the actual client IPs.

that ip (or ip range) is what your cloudflared is connecting to discourse from, so it depends on your setup. one way to be sure is to look in the nginx log file and grab the ip from there. and then add a `/32` afterwards.

if you’re following his guide exactly, i would guess that it’s `127.0.0.1/32`

> [@kuydiyadri](#):
>
> how about this…? i must use this command inside or outside container?

nah, that was just a suggestion for the `cloudflare.template.yml` template – which you shouldn’t be using in this setup.

just follow his guide in the first post but ignore the step of adding that template to your config. instead of that, [add the hook i provided](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/42).

---

<div class="post-metadata">

### Author: ![kuydiyadri](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuydiyadri/32/305813_2.png) [@kuydiyadri](https://meta.discourse.org/u/kuydiyadri)
#### Post date: [27 במאי,‏ 2023,‏ 3:56pm UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/47 "2023-05-27T15:56:31Z")

</div>

> [@shyguy](#):
>
> ```plaintext
> hooks:
> after_web_config:
> - file:
> path: /etc/nginx/conf.d/cloudflare_tunnel_real_ip.conf
> contents: |
> # restore original visitor IPs (ngx_http_realip_module)
> set_real_ip_from 10.100.20.200/32; # your cloudflared/argotunnel IP range
> real_ip_header CF-Connecting-IP;
> 
> ```

i have follow your setup. but didnt work

```plaintext
[27/May/2023:15:49:45 +0000] "sub.domain.ltd" 172.17.0.1 "POST /
[27/May/2023:15:49:45 +0000] "sub.domain.ltd" 172.17.0.1 "POST /
[27/May/2023:15:49:46 +0000] "sub.domain.ltd" 172.17.0.1 "GET /chat
[27/May/2023:15:49:46 +0000] "sub.domain.ltd" 172.17.0.1 "POST /message-bus
[27/May/2023:15:49:54 +0000] "sub.domain.ltd" 172.17.0.1 "POST /message-bus/

```

* * *

```plaintext
hooks:
  after_web_config:
    - file:
        path: /etc/nginx/conf.d/cloudflare_tunnel_real_ip.conf
        contents: |
          # restore original visitor IPs (ngx_http_realip_module)
          set_real_ip_from 172.17.0.1/32; # your cloudflared/argotunnel IP range
          real_ip_header CF-Connecting-IP;

```

where i got wrong? please help @shyguy

---

<div class="post-metadata">

### Author: ![shyguy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/shyguy/32/295079_2.png) [@shyguy](https://meta.discourse.org/u/shyguy)
#### Post date: [3 ביוני,‏ 2023,‏ 6:35pm UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/48 "2023-06-03T18:35:55Z")

</div>

bummer. that looks correct to me, so i’m not sure what’s wrong.

here is how this is supposed to work:

- cloudflare proxy adds a `CF-Connecting-IP` header containing the client’s IP
- nginx in discourse has been compiled with `ngx_http_realip_module` – software that reads this header and fixes logs etc to show actual client IP
- `set_real_ip_from` enables this feature for connections from IP ranges passed to it. this would normally be cloudflare’s IP ranges (supplied by the `cloudflare.template.yml` convenience template), but since you’re using argotunnel, you would just use argotunnel’s IP instead.

try disabling my hook. do you see the same IP in your nginx logs before/after?

* * *

probably the only difference in our setups is that i’m running argotunnel (cloudflared) in docker.

if you want to try that…

i created a network just for cloudflared:

```bash
docker network create --subnet 10.200.10.0/24 cf_tunnel

```

here is the compose file:

```yaml
services:
  cloudflared:
    image: cloudflare/cloudflared:latest
    container_name: cloudflared
    command: tunnel run
    restart: unless-stopped
    networks:
      wan:
      cf_tunnel:
        # for ngx_http_realip_module
        # set to a high IP so that hopefully docker doesn't DHCP assign
        # another container that IP if it starts before cloudflared
        ipv4_address: 10.200.10.200 # this is the ip for `set_real_ip_from` in nginx

    volumes:
      # should be owned by uid:gid 65532:65532
      - ./conf:/home/nonroot/.cloudflared

networks:
  cf_tunnel:
    external: true # just means a network not managed by compose

# for performance:
# https://github.com/quic-go/quic-go/wiki/UDP-Receive-Buffer-Size
# sudo nano /etc/sysctl.conf
  # add this line:
  # net.core.rmem_max=2500000
  # (my old value was 212992 – check it with: sudo sysctl net.core.rmem_max)

```

you can transfer your config/cert to it in that `conf` dir (remember to `chown` like the note in the compose file says) or just go through the setup procedure again. you can run cloudflared commands to log in or whatever like this:

```plaintext
docker run -it --rm -v /path/to/conf:/home/nonroot/.cloudflared cloudflare/cloudflared:latest YOUR_CMD_HERE

```

and then you have to join your discourse container to the network. you can do that with this at the bottom of your container yml:

```yaml
docker_args:
  - '--network=cf_tunnel' # optionally, you could set a static IP here too

```

---

<div class="post-metadata">

### Author: ![rsmithlal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rsmithlal/32/220716_2.png) [@rsmithlal](https://meta.discourse.org/u/rsmithlal)
#### Post date: [5 בינואר,‏ 2024,‏ 12:42am UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/49 "2024-01-05T00:42:38Z")

</div>

Does anyone have success getting the discourse incoming mail server container working over the cloudflare tunnel?

I’ve had trouble setting up another mail server behind the cloudflare tunnel in the past, but I can get apps running on my Pi that use ports 80 and 443 working fine.

I’ve set up Discourse on servers multiple times and I’m not too concerned about the main Discourse container for now.

I think this is related, but please create a new post from my reply if you feel that it’s off-topic.

Thank you.

---

<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: [5 בינואר,‏ 2024,‏ 11:59am UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/50 "2024-01-05T11:59:37Z")

</div>

> [@rsmithlal](#):
>
> Does anyone have success getting the discourse incoming mail server container working over the cloudflare tunnel?

I’m pretty sure that the cloudflare tunnel is only for web traffic and not any other ports.

This suggests that I’m right [https://community.cloudflare.com/t/can-i-create-a-mail-server-with-cloudflare-tunnel/386089](https://community.cloudflare.com/t/can-i-create-a-mail-server-with-cloudflare-tunnel/386089)

---

<div class="post-metadata">

### Author: ![kuaza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuaza/32/264151_2.png) [@kuaza](https://meta.discourse.org/u/kuaza)
#### Post date: [13 במאי,‏ 2024,‏ 7:45pm UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/51 "2024-05-13T19:45:35Z")

</div>

I used the argo service. I gave up when I paid 28 euros for the first month. There was actually at least a 200ms difference. However, I canceled it because I could not afford to pay 28 euros every month for 200 ms. Larger sites will have more invoices, keep in mind.

The site’s hit is 800-1000 unique users. You can calculate accordingly.

---

<div class="post-metadata">

### Author: ![Genisis](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@Genisis](https://meta.discourse.org/u/Genisis)
#### Post date: [17 במאי,‏ 2024,‏ 7:26pm UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/53 "2024-05-17T19:26:34Z")

</div>

Also ever since I started using tunnel, uploading media has been a hassle or next to impossible  
Uploads normally then I get this error

 ![IMG_1002](https://global.discourse-cdn.com/meta/original/4X/2/e/9/2e94e1810f5c91841e092db43b82e8d280b8d620.jpeg)

---

<div class="post-metadata">

### Author: ![Genisis](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@Genisis](https://meta.discourse.org/u/Genisis)
#### Post date: [19 במאי,‏ 2024,‏ 4:18pm UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/55 "2024-05-19T16:18:07Z")

</div>

when running `apt-get update` I got this error

 ![image](https://global.discourse-cdn.com/meta/original/4X/4/9/f/49f4a6735feb3e0278eaede81f34956030a78ef7.png)

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [19 במאי,‏ 2024,‏ 6:18pm UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/56 "2024-05-19T18:18:20Z")

</div>

You need to run a 64 bit OS 😅

---

<div class="post-metadata">

### Author: ![Genisis](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@Genisis](https://meta.discourse.org/u/Genisis)
#### Post date: [19 במאי,‏ 2024,‏ 8:22pm UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/57 "2024-05-19T20:22:44Z")

</div>

That’s the thing lol it is 64bit. But I figured it out. I did apt get upgrade and restarted cloudflare service and it uploaded. Also do you know if cloudflare limit the upload of videos with tunnel? I’m having issues uploading like a 20MB video and I didn’t before

 ![IMG_1002](https://global.discourse-cdn.com/meta/original/4X/2/3/f/23ffa28ac6a9cf194c69d557eaa2b30b9cdccb8e.jpeg)

---

<div class="post-metadata">

### Author: ![Tobiasp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiasp/32/297645_2.png) [@Tobiasp](https://meta.discourse.org/u/Tobiasp)
#### Post date: [11 ביוני,‏ 2024,‏ 8:41am UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/58 "2024-06-11T08:41:57Z")

</div>

I have set up the Cloudflare tunnel and it is also active:

 ![cloudflare-tunnel-settings](https://global.discourse-cdn.com/meta/original/4X/6/e/b/6ebd566189b475d10123022fdd927c1c9c85e7fb.png)

However, the error that Discourse cannot reach the domain always appears during installation.  
I have written DISCOURSE\_FORCE\_HTTPS: true in the App.yml.

However, I did not cancel the installation, but it was automatically canceled before I could change the App.yml. Could this be the error?

---

<div class="post-metadata">

### Author: ![joshhabka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshhabka/32/452328_2.png) [@joshhabka](https://meta.discourse.org/u/joshhabka)
#### Post date: [28 בספטמבר,‏ 2024,‏ 10:21pm UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/59 "2024-09-28T22:21:26Z")

</div>

Same, @Tobiasp did you fix it yet? If so, how? Thank you

---

<div class="post-metadata">

### Author: ![Tobiasp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiasp/32/297645_2.png) [@Tobiasp](https://meta.discourse.org/u/Tobiasp)
#### Post date: [28 בספטמבר,‏ 2024,‏ 11:41pm UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/60 "2024-09-28T23:41:32Z")

</div>

I have a public IP and used that for the installation. Then I installed Cloudflare Tunnel.

---

<div class="post-metadata">

### Author: ![joshhabka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshhabka/32/452328_2.png) [@joshhabka](https://meta.discourse.org/u/joshhabka)
#### Post date: [28 בספטמבר,‏ 2024,‏ 11:51pm UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/61 "2024-09-28T23:51:09Z")

</div>

Can you send me your configurations and stuff and how you did it? Thank you!

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [29 בספטמבר,‏ 2024,‏ 7:04am UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/62 "2024-09-29T07:04:35Z")

</div>

And just to keep all stuff and solutions together:

> [@Cloudflare Tunnels - Discourse Setup Not Recognizing Hostname (Port not accessible)](https://meta.discourse.org/t/cloudflare-tunnels-discourse-setup-not-recognizing-hostname-port-not-accessible/328520/):
>
> I have the cloudflared daemon running properly and have used it for tons of stuff(meaning the tunnel is installed properly on the server), but I am having trouble getting the Discourse setup(./discourse-setup) to recognize my hostname for my Discourse instance. I am using biohacking.forum as the hostname for my instance. This my my Cloudflare Tunnel configuration for biohacking.forum: I have also tried setting it to HTTPS for the service type I am …

---

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [15 באוקטובר,‏ 2024,‏ 10:42am UTC](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297/63 "2024-10-15T10:42:55Z")

</div>

When following the guide, it needs us to choose whether to connect a network or an application. Which should we choose?

[Previous page](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297.md?page=2)

[Next page](https://meta.discourse.org/t/install-discourse-on-a-residential-internet-with-cloudflare-tunnel/211297.md?page=4)
