NextCloudをCloudflare Tunnelで公開し、かつLAN内からは直接接続する

未分類

つまりWANからはCloudflare Tunnelを使って自宅のNextCloudに接続したいが、LAN内では速度の面で直接接続したいってことよ(?)

NextCloud All in One (Docker)でNextCloudを起動

ここ(https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md)を参考にCloudflare Tunnel用にDokcerでなんやかんやします。
[メモ]使ったのが↓

sudo docker run \
--sig-proxy=false \
--name nextcloud-aio-mastercontainer \
--restart always \
--publish 8080:8080 \
--env APACHE_PORT=11000 \
--env APACHE_IP_BINDING=0.0.0.0 \
--env SKIP_DOMAIN_VALIDATION=true \
--env NEXTCLOUD_DATADIR="/mnt/nextcloud" \
--volume nextcloud_aio_mastercontainer:/mnt/docker-aio-config \
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
nextcloud/all-in-one:latest

あとは使うドメインでNextCloudをセットアップします。

ドメインをローカルIPに解決させる

ルータがOpenWRTを使っているのでOpenWRTを使います。
OpenWRTの管理画面 -> 上メニューのネットワーク -> DHCPおよびDNS -> 画面の真ん中にあるアドレス一覧/nd.example.com/#/192.168.1.150みたいに入力して適用します。

あとはLAN内からping nd.example.comとしてローカルIPに解決したらOK

Caddyをいれていい感じに証明書を取得してもらう

NextCloudをリバースプロキシ用としてセットアップした&SSLでしか接続できないのでこのままだと接続しても使えません。

そこで再びここ(https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md)を参考に(Caddy with ACME DNS-challenge)して証明書をいいかんじにしてもらいます。

CaddyのダウンロードからCloudflareモジュールをクリックしてダウンロード
→バイナリをパスの通った適当な場所に置いておく
→Caddyfileという名前でファイルを作り設定を書く
caddy run --config path/to/Caddyfile

Caddyfileに書く設定にはAPI Tokenがいりますが、ここを見ると

  • Zone / Zone / Read
  • Zone / DNS / Edit

で用意しろと書いてあるのでそのとおりにTokenを取得します

Caddyfile
# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name.
{
	admin 0.0.0.0:2020
}
https://nc.example.com:443
{ reverse_proxy localhost:11000 tls { dns cloudflare <cloudflare_api_key> } } # Refer to the Caddy docs for more information: # https://caddyserver.com/docs/caddyfile

DNSをOpenWRTの入ったルータに問い合わせるようになっていない(8.8.8.8を設定してるとか)と、当然のことながらCloudflare Tunnel経由でつながるので気をつけましょう(2敗)

コメント

タイトルとURLをコピーしました