traefik v2 https 上游 upstream 邊緣 Edge Gateway 博客園
---【前言】---
k4t國產k8s,qq群號:722528388
為了給【國產k8s】選幾款網關,我盯上了歐洲人開發的老牌網關traefik,
因為沒有中文網站和社區支持,自己研究很費勁,
我把經驗總結下來,給大家使用,
---【正文】---
---【特色&優缺點】---
* 支持win中使用,這很好,很方便,
* 支持http,https,發送api,
* 支持etcd,redis,云存盤等作為存盤資料面,
* 支持watch目錄,
* 動態組態檔名支持中文,擴展名支持yaml,toml,只需要把某個路由擴展名改成.txt,即代表洗掉此路由,
* 動態組態檔只支持utf8,無bom頭編碼,支持井號開始的注釋,但盡量單獨一行,支持中文注釋,靜態組態檔不支持中文,
* 基于分布式資料庫,或者頻繁復制檔案,達到資料面高可用,
* 自帶dashboard,但免費版只能看,不能編輯,建議測驗服打開,作業服關閉dashboard,
* 位于歐洲,github上不接受技術支持,公司自建論壇只支持英文,論壇中文郵箱注冊不上,
* 中文網站,論壇很不活躍,討論基本沒有,難以獲取支持,
我發現自從2021年中開始,網上學習研究這個網關的就開始減少了,
這也是我寫本文的目的,希望本文能給這個網關注入點活力,
---【弄好的組態檔例子】---
在:
https://gitee.com/chuanjiao10/powershell/tree/master/gateway_client/traefik
baidu.toml:本文代碼,
zhengze3.toml.txt:正則替換的例子,
默認不起作用,需要把baidu.toml改名,然后把此檔案改名成toml
http2http.toml: 從http路由,轉http上游
openssl.conf:證書組態檔,
traefik.toml:啟動用的靜態組態檔,
---【用traefik配置邊緣網關,并使用https上游】---
這里先要把 test223.com ,在host檔案中指向本機,
對于win,就是:
c:\Windows\System32\drivers\etc\host檔案中寫入:
127.0.0.1 test223.com
然后:
目的:所有http,都轉https
[http.routers] [http.routers.my-router] rule = "Host(`test223.com`) && PathPrefix(`/baidu`)" middlewares = "redirect2https" entryPoints = "web" service = "noop@internal" [http] [http.middlewares] [http.middlewares.redirect2https.redirectScheme] scheme = "https"
注意:上面的這段代碼,不能獨立作業,需要下面的代碼,
目的:從https,顯式,轉https網址
[http.routers.my-router-https] rule = "Host(`test223.com`) && PathPrefix(`/baidu`)" service = "noop@internal" entryPoints = "websecure" middlewares = "https-upstream" [http.routers.my-router-https.tls] [http.middlewares.https-upstream.redirectRegex] regex = "^https://test223.com/baidu$" replacement = "https://www.baidu.com"
---【用openssl制作,自簽名證書】---
cd a:\traefik_v2.9.10
openssl req -x509 -nodes -days 3660 -newkey rsa:2048 -keyout test223.key -out test223.cert -config A:\traefik_v2.9.10\openssl.conf
測驗:
curl.exe -kv https://test223.com/baidu
powershell v5:Invoke-WebRequest https://test223.com/baidu
powershell v7:Invoke-WebRequest https://test223.com/baidu -SkipCertificateCheck
win中,用瀏覽器測驗:
運行certmgr.msc,把證書匯入到【受信任的根證書頒發機構】,
注意,盡量使用curl,或powershell測驗,瀏覽器有時候會快取舊的路由,或上游,
變更后,即便重啟瀏覽器,也還是舊路由,舊上游,需要重啟win,有時候重啟win,也不更新,
---【謝謝觀看,完】---
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/551509.html
標籤:其他
上一篇:解密Prompt系列6. lora指令微調扣細節-請冷靜,1個小時真不夠~
下一篇:返回列表
