免責聲明:
在意識到堆疊溢位意味著編碼問題之前,我已經打開了類似的堆疊溢位問題...
我的問題:
我正在嘗試透過 ssh 隧道存取連接到我的 nginx 伺服器的 Web 服務。如果我 ssh 伺服器並捲曲隧道端口,它會完美地工作。我的下一步是在我的 nginx 配置上執行 proxy_pass,以允許我們存取給定連接埠的該服務。我堅持使用以下配置來解決它:
location ~ ^/test/([0-9]+)/ {
#allow our.ip/32;
proxy_pass http://127.0.0.1:$1/;
}
當索引載入時,它嘗試重定向到名為 login.php 的頁面(該頁面存在,我可以使用curl localhost:port/login.php 存取它)。經過一番研究,我想出了從 location 和 proxy_pass 中刪除斜杠的解決方案,使其看起來像這樣:
location ~ ^/test/([0-9]+) {
#allow our.ip/32;
proxy_pass http://127.0.0.1:$1;
}
這幾乎是您在大多數範例中發現的內容,但它不起作用。只是 502,我不明白為什麼。
編輯
這是來自請求的 nginx 錯誤日誌:
2021/01/11 14:21:49 [error] 88542#88542: *19093 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: my.server.address, request: "GET /test/1480/ HTTP/2.0", upstream: "http://127.0.0.1:1480/test/1480/", host: "my.server.address"
它不應該將“/test/”傳遞給遠端主機...