我想要的效果:
http://hostname/proxy/3000
http://127.0.0.1:3000
http://hostname/proxy/3000/anything
http://127.0.0.1:3000/anything
有一個要求:連接埠是變化的
我嘗試了
location ~ /proxy/(\d+) {
proxy_pass http://127.0.0.1:;
rewrite ^/(.*)$ / break;
}
但是rewrite不管怎麼寫都有問題
在nginx的配置該怎麼寫,在線等~
proxy_pass
的文檔里有講:location
使用了正則后,proxy_pass
指令後面的參數(shù)中的 URI 部分會被忽略??梢允褂孟旅娴呐渲瞄g接達到你想要的功能:
server {
listen 80;
server_name localhost;
location /proxy/ {
rewrite ^/proxy/(\d+)/(.*) /internal?port=&url= last;
}
location /internal {
internal;
proxy_pass http://127.0.0.1:$arg_port/$arg_url;
}
}