주거용 인터넷 환경에서 Cloudflare Tunnel을 이용해 Discourse 설치하기

Discourse가 이제 Raspberry Pi에서 실행되도록 지원되고 있으므로, 홈 랩에서 작은 인스턴스를 실행하는 것이 일반적인 사용 사례가 될 것입니다. 그러나 많은 주거용 ISP는 Discourse에 필요한 80/443 포트에 대한 수신 트래픽을 차단합니다.

https://discourse-on-a-pi.falco.dev/ 의 데모 사이트에서는 Cloudflare Tunnel을 사용하여 이를 우회했으며, 여러분도 그렇게 할 수 있습니다!

터널 설정

먼저 다음 가이드를 따르세요:

필요한 유일한 변경 사항은 URL을 url: http://localhost:8000에서 url: http://localhost:80으로 변경하는 것입니다. 터널은 이미 백그라운드에서 실행 중이므로 그대로 두세요.

Rocket Loader 비활성화

Discourse가 올바르게 작동하려면 Cloudflare Rocket Loader를 비활성화해야 합니다.

https://community.cloudflare.com/t/how-can-i-remove-the-rocket-loader-script-from-the-header-tag-on-my-website/4229/2

Discourse 설치

How to install Discourse in production을 따르되, app.yml 파일이 생성되고 5초 카운트다운이 표시되면 CTRL+C를 누르세요.

이제 파일의 첫 번째 줄들을 다음과 같이 편집하세요:

templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/cloudflare.template.yml"
#  - "templates/web.ratelimited.template.yml"
## Lets Encrypt(https)를 추가하려면 이 두 줄의 주석을 해제하세요
#  - "templates/web.ssl.template.yml"
#  - "templates/web.letsencrypt.ssl.template.yml"

그리고 env: 섹션 아래에 다음 줄을 추가하세요:

DISCOURSE_FORCE_HTTPS: true

그 다음 ./launcher rebuild app을 실행하세요.

기다리는 동안 터널/discourse 설정에서 사용한 도메인으로 항상 HTTPS로 리디렉션하도록 페이지 규칙을 설치하세요:

몇 분 안에 터널/discourse 설정에서 사용한 도메인으로 새로운 Discourse 인스턴스가 사용 가능해집니다 :tada:."

39개의 좋아요

I think it’s better that mention about port. If user decide to use argo tunnel, then they need to setup their port the same as tunnel settings. For example:

-80:80
#-443:443

then they need to let the tunnel listen
http://localhost:80

What I use is use unix socket to connect them.

5개의 좋아요

Isn’t that what I mention here:

?

7개의 좋아요

Hi Rafael,

Thanks for the tutorial.

I’ve followed everything as per your guide above and everything works fine however;

Upon clicking on the link in the email to activate my account I get flown back to the correct webpage with an activation button, however this button doesn’t work. I’ve looked up guidance on this forum and it looks like a domain to ip issue?

I have confirmed force_https is set to true in the config.

Any thoughts / did you run into this issue (Screenshot attached) of the button that doesn’t do anything?

3개의 좋아요

Alright so I managed to fix this.

Just ensure rocket loader is disabled :wink:

Cheers!

6개의 좋아요

Finally, installed Discourse on Raspberry Pi. But i have problems with Cloudflare Tunnels.

I can’t access to Discourse site with domain, something strange in the config.yml configuration?

url: http://localhost:80
tunnel: 371dd57c-************
credentials-file: /home/pi/.cloudflared/371dd57c-*********.json
3개의 좋아요

What is the tunnel command output? It should be explicit about any mistakes you made on the configuration.

3개의 좋아요

cloudflared tunnel info output:

cloudflared tunnel info ******
2022-01-24T04:55:47Z INF Cannot determine default origin certificate path. No file cert.pem in [~/.cloudflared ~/.cloudflare-warp ~/cloudflare-warp /etc/cloudflared /usr/local/etc/cloudflared] originCertPath=
2022-01-24T04:55:47Z ERR You need to specify the origin certificate path with --origincert option, or set TUNNEL_ORIGIN_CERT environment variable. See https://developers.cloudflare.com/argo-tunnel/reference/arguments/ for more information. originCertPath=
error parsing tunnel ID: Error locating origin cert: client didn't specify origincert path when running from terminal
2개의 좋아요

Looks like you misplaced the certificate file? If you are running as root, the file should be under

/root/.cloudflared/

and not where you put it as

2개의 좋아요

I have already cert.pem file.

2개의 좋아요

And are you trying to start the tunnel as the pi user or as root?

3개의 좋아요

I am using this command as pi user

cloudflared tunnel run <UUID or NAME>

2개의 좋아요

Hi @bekircem,

It looks like your Cloudflared has been able to initiate a connection to Cloudflare’s edge.

Have you enabled the Routing with a CNAME to your Argo Tunnel ID on Cloudflare?

Cheers,

Alex.

3개의 좋아요

Hi @Stigin, thank you for the reply.

Yes, i am enabled routing from the command line

2개의 좋아요

Interesting one @bekircem - Hmm!!

What is the current error you’re getting when browsing to your website address? Is it just a generic Cloudflare Argo Tunnel error page?

Could you please show us your running containers by running the command: docker ps and show us your current running tunnels with cloudflared tunnel list || Make sure you blur out your argo route / any non-relevant containers! :wink:

Alex.

3개의 좋아요

What is the current error you’re getting when browsing to your website address? Is it just a generic Cloudflare Argo Tunnel error page?

No there is no Cloudflare Argo Tunnel error page.

ERR_NAME_NOT_RESOLVED

docker ps

CONTAINER ID   IMAGE                 COMMAND        CREATED        STATUS        PORTS                                                                      NAMES
f1bde9b70f55   local_discourse/app   "/sbin/boot"   11 hours ago   Up 11 hours   0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp   app

When use this command as a root user cloudflared tunnel list

2022-01-24T15:55:03Z INF Cannot determine default origin certificate path. No file cert.pem in [~/.cloudflared ~/.cloudflare-warp ~/cloudflare-warp /etc/cloudflared /usr/local/etc/cloudflared] originCertPath=
2022-01-24T15:55:03Z ERR You need to specify the origin certificate path with --origincert option, or set TUNNEL_ORIGIN_CERT environment variable. See https://developers.cloudflare.com/argo-tunnel/reference/arguments/ for more information. originCertPath=
Error locating origin cert: client didn't specify origincert path when running from terminal

When use this command as a pi user cloudflared tunnel list

You can obtain more detailed information for each tunnel with `cloudflared tunnel info <name/uuid>`
ID                                   NAME      CREATED              CONNECTIONS
371dd57c-**************** ze****2022-01-24T03:35:19Z

It is normal?

We need to use a subdomain for DISCOURSE_HOSTNAME in the config.yml file, right?

Update: I am uninstalled Cloudflared and reinstalled with root user and it works now. I still don’t understand where exactly I went wrong in my previous attempt.

2개의 좋아요

어떤 식으로든 결국 라즈베리파이에서 사이트를 구동해서 라이브를 올렸습니다.

정확히 어떻게 된 건지 잘 모르겠습니다. Cloudflared를 제거한 뒤 root 사용자 계정으로 다시 설치했는데, 그랬더니 작동하네요…

질문이 두 가지 있습니다.

  1. SSL 인증서가 제대로 작동하지 않는 것 같아서 Discourse 관리자 계정에 로그인할 수 없습니다. (시크릿 탭에서 실행되는 것처럼 보입니다. 캐시 관련 문제일 수도 있겠네요.) full 설정을 사용 중이신가요, 아니면 full(strict)를 사용 중이신가요?

  1. cloudflared를 서비스로 실행하는 방법에 대해 질문이 있습니다. https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/run-tunnel/run-as-service

cloudflared tunnel run <UUID or NAME> 명령어로 터널을 실행했습니다. 그런데 터미널 창을 닫으면 터널이 멈추는 건가요?

이미 로그인했고 ~/.cloudflared/에 설정 파일이 있는 경우, 해당 파일이 /etc/cloudflared/로 복사됩니다.

설정 파일이 없는 경우, 위에 나열된 필드를 포함하는 config.yml 파일을 직접 생성해야 합니다. cloudflared --config CONFIG-FILE service install 명령을 실행하여 사용자 지정 파일을 전달할 수 있습니다.

확인해 보니 /etc/cloudflared/에 설정 파일이 없습니다. 이 경우 이 서비스를 자동으로 실행하려면 어떻게 해야 하나요?

감사합니다.

2개의 좋아요

Questions that are more specific about the Cloudflare tunnel service may receive better answers at https://community.cloudflare.com/tag/cloudflaretunnel

3개의 좋아요

Hey @bekircem,

I think reinstalling it would of fixed the issue of cloudflared not finding the certificate…

With regards to running Cloudflare as a service - the configuration file you created when running the service manually will need to be moved to /etc/cloudflared.

I’m unsure about linking personal sites here so please let me know if I need to remove this but I’ve covered this under my one of my blogs under the section called: ‘Setup and Run Cloudflared as a Service

Let us know how you get on!

Alex.

4개의 좋아요

Thank you for the reply.

Great blog post, thanks for sharing.

Run Cloudflared as a Service

sudo cloudflared service install

config.yml file automatically copied to /etc/cloudflared/.

sudo systemctl start cloudflared

sudo systemctl enable cloudflared

And it’s working great. I haven’t tried rebooting yet but I hope it will work.

4개의 좋아요