簡體   English   中英

Nginx 從同一位置代理到多個端口

[英]Nginx Proxy to multiple ports from same location

我目前有這個配置

server { 
listen 4000;
location / {
    proxy_pass http://websocket;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header Host $host;
    proxy_redirect off;
}
upstream websocket {
    server localhost:4444;
}
upstream websocket2 {
    server localhost:4445;
}

使用此配置,來自 localhost:4000 的所有請求都被代理到 localhost:4444。 我不想只將這些請求代理到 localhost:4444 也不想代理到 localhost:4445

localhost:4000 代理請求

  • 本地主機:4444
  • 本地主機:4445

可能嗎?

此處的 Nginx 文檔中,您可以聲明具有多個服務器的上游。 然后你可以將流量轉發到這個上游,流量將在服務器之間調度。 因此,只需將您的服務器放入 1 個上游websocket即可歸檔您想要的內容。

upstream websocket {
    server localhost:4444;
    server localhost:4445;
}

server { 
    listen 4000;
    location / {
        proxy_pass http://websocket;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header Host $host;
        proxy_redirect off;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM