我用yarn啟動app,在本地機器上配置一個本地nginx服務監聽8083埠,yarn服務監聽3000埠,當url路徑以 開頭時/manage,將http請求轉發到后端服務部署中遠程 Kubernetes 集群。這是我的本地 nginx 轉發配置:
server {
listen 8083;
server_name admin.reddwarf.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
location ^~ /manage/ {
proxy_pass https://admin.example.top;
proxy_redirect off;
proxy_set_header Host https://admin.example.top;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
在 kubernetes 集群中,我使用 traefik 轉發 http 請求,它通過 httphost標頭轉發。這是 traefik 配置:
routes:
- kind: Rule
match: Host(`admin.example.top`) && PathPrefix(`/manage`)
priority: 2
services:
- name: dolphin-gateway
port: 8081
現在 http 請求給出 404 not found 錯誤,我確定 api 路徑存在,因為我可以在測驗工具中呼叫 api。我認為從本地除錯應用程式發送的請求是localhost:8083使 traefik 無法正確識別請求。我應該怎么做才能將本地機器標頭更改為admin.example.top使 traefik 可以識別?還是我的配置有誤?我應該怎么做才能讓它按預期作業?這是本地請求演示:
curl 'http://localhost:8083/manage/admin/user/login' \
-H 'Connection: keep-alive' \
-H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96"' \
-H 'Accept: application/json, text/plain, */*' \
-H 'DNT: 1' \
-H 'Content-Type: application/json;charset=UTF-8' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36' \
-H 'sec-ch-ua-platform: "macOS"' \
-H 'Origin: http://localhost:8083' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Referer: http://localhost:8083/' \
-H 'Accept-Language: en,zh-CN;q=0.9,zh;q=0.8,zh-TW;q=0.7,fr;q=0.6' \
--data-raw '{"phone":" 8615623741658","password":"123"}' \
--compressed
uj5u.com熱心網友回復:
嘗試添加到 curl 請求:-H 'HOST: admin.example.top'。然后更新你的 nginx 配置:
server {
listen 8083;
server_name admin.example.top;
...
與 HOST 匹配的服務器塊將處理請求。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/392556.html
標籤:http nginx Kubernetes
