OpenWrtでリバースプロキシとSSL/TLS終端をする
OpenWrt化したWSR-2533DHP2で宅内にあるウェブアプリへのアクセスをHTTPSでしたかったので、acme.shとhaproxyで環境を作った。[OpenWrt Wiki] Get a free HTTPS certificate from LetsEncrypt for OpenWrt with ACME.shopenwrt.orgGitHub - acmesh-official/acme.sh: A pure Unix shell script ACME client for SSL / TLS certificate automationA pure Unix shell script ACME client for SSL / TLS certificate automation - acmesh-official/acme.shgithub.comHAProxy - The Reliable, High Perf. TCP/HTTP Load BalancerReliable, High Performance TCP/HTTP Load Balancerwww.haproxy.orgacme.shはシェルスクリプトで実装された軽量なcertbotのようなものだそうだ。これで証明書の取得や更新を行う。OpenWrtならopkgからacme(はエイリアスのような感じでacme-acmeshが実体らしい)をインストールすると使える。さらにLuCIのUIであるluci-app-acmeをインストールすると管理画面からポチポチ操作で設定できる(なんだかんだCLIでの操作などは必要になると思うが)。HAProxyはロードバランサーらしいがリバースプロキシ用途にも使える。来たものをそのままどこかに送り出すという意味ではどちらも同じか。OpenWrtならopkgからhaproxyをインストールできる。DNSはOpenWrtに最初から入っているdnsmasqを使った(AIにunboundもどうですかと勧められたが空き容量が気になるしdnsmasqで十分だったのでそのままにした)。LuCIの配信のために最初から入っているuhttpdのポートを変更してHAProxyでLuCIにリダイレクトするようにしたことで管理画面にもきちんとアクセスできる。Unbound - AboutUnbound is a validating, recursive, caching DNS resolver. It is designed to be fast and lean and incorporates modern features based on open standards. To help increase online priva…nlnetlabs.nlGitHub - NLnetLabs/unbound: Unbound is a validating, recursive, and caching DNS resolver.Unbound is a validating, recursive, and caching DNS resolver. - NLnetLabs/unboundgithub.comHAProxy以外にはnginx-sslがあるのでこれをインストールして使うなどの方法がある。今回はNginxほど多機能なものを使う必要がなさそうだったのでHAProxyにしておいた。luci-nginxのパッケージはなんなのかもわかっていない。空き容量が潤沢にある場合にはNginx Proxy ManagerやCaddyを使うと楽らしい。Nginx Proxy ManagerDocker container and built in Web Application for managing Nginx proxy hosts with a simple, powerful interface, providing free SSL support via Let's Encryptnginxproxymanager.comGitHub - NginxProxyManager/nginx-proxy-manager: Docker container for managing Nginx proxy hosts with a simple, powerful interfaceDocker container for managing Nginx proxy hosts with a simple, powerful interface - NginxProxyManager/nginx-proxy-managergithub.comCaddy - The Ultimate Server with Automatic HTTPSCaddy is a powerful, enterprise-ready, open source web server with automatic HTTPS written in Gocaddyserver.comGitHub - caddyserver/caddy: Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPSFast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS - caddyserver/caddygithub.com実際、試しにNginx Proxy ManagerをProxmoxのコンテナとして建てて使ってみたが楽だった。WSR-2533DHP2の使い道に困っていたが、割と重要な役割になってきてむしろセカンダリやバックアップが必要なのでは?と思ってきた…… 中古ではあるし何かあったらOrange Pi R2Sに交換しよう。