簡體   English   中英

nginx代理重定向與uri的端口

[英]nginx proxy redirection with port from uri

我正在嘗試使用nginx進行重定向。 想法是將uri / id_1234 /重定向到localhost:1234以用於某些端口。 固定端口的重定向:

location /id_1234/ {
    rewrite ^/id_1234/(.*) /$1 break;
    proxy_pass http://localhost:1234;
    proxy_redirect http://localhost:1234/ $scheme://$host/id_1234/;
}

它工作得很好。 現在我嘗試將1234更改為任何端口:

location ~* ^/id_([0-9]*)/ {
    rewrite ^/id_([0-9]*)/(.*)$ /$2 break;
    proxy_pass http://localhost:$1;
    proxy_redirect http://localhost:$1/ $scheme://$host/id_$1/;
}

使用此配置,我收到502錯誤,日志中出現以下錯誤:

no resolver defined to resolve localhost

如果我在localhost:之后將$ 1更改為實際端口,則它適用於指定的端口。 如何使用正則表達式指定重定向端口?

提前致謝!

添加

resolver 127.0.0.1;

有幫助,但很奇怪......

跟隨@ alleb57的回答 - 似乎在配置的這一點上沒有localhost的定義。 我在整個配置中轉換為使用http://127.0.0.1 (通過localhost ),您不必定義解析器。

暫無
暫無

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

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