我想使用Nginx創建一個網關來接收請求,并將它們傳遞給一個微服務網路。
我需要Nginx做的只是作為一個代理服務器,接收請求,將它們傳遞給任何服務,并回傳回應,不做任何改變。
這是我在本地設定中的配置:
server {
listen 8080;
location /api/register/ {
proxy_pass http://micro_auth_backend:8082。
}
位置 /api/location/ {
proxy_pass http://localhost:8088。
}
}
它在GET請求中作業正常,但是當進行POST呼叫時,服務器將始終收到一個GET回應。
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
如果有任何建議,我們將不勝感激。 謝謝你
uj5u.com熱心網友回復:
你可以在你的nginx.conf檔案中加入這段代碼。它對我很有效。
location /api/register/ {
proxy_pass http://localhost:8082。
proxy_http_version 1.1;
proxy_set_header 升級 $http_upgrade。
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /api/location/ {
proxy_pass http://localhost:8088。
proxy_http_version 1.1;
proxy_set_header 升級 $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
uj5u.com熱心網友回復:
只要去掉location上的尾部斜線即可:
location /api/register {
proxy_pass http://micro_auth_backend:8082。
}
現在可以了。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/320485.html
標籤:
