我猜很多 web devs(網頁開發者)都知道什麼是反向代理伺服器 (Reverse Proxy Server)。當您在 homelab 或 cluster 上部署多個 service 並希望使用單一gateway server 和不同 subdomain 將它們 expose 在網際網路上時,反向代理伺服器尤其有用。在這篇部落格文章中,我就來分享一下我為什麼要用 Go 開發自己的反向代理伺服器來取代Apache / Nginx 和把它部署到我的分散式 homelab 中的經驗。
甚麼是 Reverse Proxy?
想像一下,你正在音樂節上隨著你最喜愛的表演,突然你想要一杯 冰涼的飲料。由於你不想錯過任何的表演環節,所以你派你的好朋友(即反向代理伺服器),去替你把飲料拿來(網頁內容)。你的朋友穿過人群,排隊等候,完全不會打擾你觀賞表演,最後在不知甚麼時候帶回了那杯冰涼的飲料。在這種情況下,反向代理伺服器扮演著你和音樂節混亂背後的幕後伺服器之間的中間人角色,隔離你(用戶)和後面混亂的內部網絡 routing,直接由中間人向你提供所需的內容。
不僅僅是為你轉發和中繼網頁內容 ,現代的反向代理可做到比中繼代理之外更多的事情。例如說負載平衡、故障切換(failover)等。像Nginx Proxy Manager(NPM,不是那個黑洞 npm)這樣的管理工具甚至具有內置的自動 SSL證書更新等功能。這就是為什麼反向代理通常被認為是 homelab(或任何類型的網站系統)的“核心”的原因。
那為甚麼我要重新寫一個屬於自己的 Reverse Proxy 伺服器?
如果你是一名資深的 devops 工程師,那你一定有親身體驗過寫 Apache 或 Nginx 配置文件的痛苦,那必定是一個難以忘懷的經歷。當你試圖從 Stack Overflow上 Copy & Paste 一些看不懂的東西到你的 config 檔,並試著根據自己的了解進行修改,卻發現怎樣 route 都是怪怪的。再加上很多開源專案都很依賴於 Rewrite Rules 和 Headers 中某些特殊設置的 Setting,要讓所有 service 都能正常運行真是一件讓人痛苦的事情。更多別提到你想加入一個臨時的 routing rules 做 testing 都要進入 ssh 到後台設置的麻煩(
在開源世界中,有一些替代方案或解決方案可解決這些問題。像 NPM 是 r/selfhost 上 Reddit 用戶最推薦的方案之一。然而,它已經快兩年沒更新了,而且聽說最新版本會弄壞很多東西。這就是為什麼我決定自己開發一個 Reverse Proxy 伺服器以解決自己未來可預見的「所有」問題。
這就是 Zoraxy 誕生的原因

Zoraxy 是一個以 Go 開發的 Reverse Proxy 伺服器。除了基本的功能外,還附了很多不同的工具和機能讓你輕易管理你的伺服器集群(當然也能用於 docker 了)。以下是一些簡單易懂的系統截圖:
















有興趣了解更多或下載試用可以到 https://zoraxy.aroz.org 看看喔