我试着用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更改为实际端口,则对于指定的端口,它可以正常工作。如何使用regex指定重定向端口?
提前感谢!
发布于 2014-08-04 07:17:19
添加
resolver 127.0.0.1;
有帮助,但很奇怪.
发布于 2014-12-31 20:31:38
下面是@alleb57 57的回答--在配置的这一点上,似乎没有localhost
的定义。我在整个配置过程中转换为使用http://127.0.0.1
(通过localhost
),您不必定义解析器。
https://stackoverflow.com/questions/25106424
复制相似问题