Nginx ngnix中的代理传递和url重写

Nginx ngnix中的代理传递和url重写,nginx,rewrite,proxypass,Nginx,Rewrite,Proxypass,使用代理传递转发请求。 如果键入的url是www.yyy.com/9.157/7.134/live/playlist.m3u8 我想把它传给10.5.a.b:1935/live/playlist.m3u8 如果前两个八位字节(10.5)保持不变,我需要做的就是从url中提取9.157和7.134,并将其代理传递到10.5.a.b:1935或(如果10.5.9.157:1935向下,则代理传递到10.5.7.134:1935) 这就是我的nginx配置的外观 地点/{ rewrite

使用代理传递转发请求。 如果键入的url是www.yyy.com/9.157/7.134/live/playlist.m3u8

我想把它传给10.5.a.b:1935/live/playlist.m3u8

如果前两个八位字节(10.5)保持不变,我需要做的就是从url中提取9.157和7.134,并将其代理传递到10.5.a.b:1935或(如果10.5.9.157:1935向下,则代理传递到10.5.7.134:1935)

这就是我的nginx配置的外观

地点/{

       rewrite (\/)(([0-9][0-9][0-9]|[0-9][0-9]|[0-9])\.([0-9][0-9][0-9]|[0-9][0-9]|[0-9]))(\/)  http://10.5.$2:1935/live/suhas_712_media_240p/playlist.m3u8  redirect;

}
上面的代码正在工作,但是我不想重定向,我想做如下的事情

代理通行证10.5.a.b:1935

如何将提取的值传递给a、b

谢谢

这应该可以:

(为了清楚起见,我使用了)

位置~*“/(?)

>GET/9.157/7.134/live/playlist.m3u8 HTTP/1.1
...
>用户代理:curl/7.43.0
>接受:*/*
>
这应该可以:

(为了清楚起见,我使用了)

位置~*“/(?)

>GET/9.157/7.134/live/playlist.m3u8 HTTP/1.1
...
>用户代理:curl/7.43.0
>接受:*/*
>
   location ~* "/(?<a>[0-9]{1,3}\.[0-9]{1,3})/(?<b>[0-9]{1,3}\.[0-9]{1,3})/(?<suffix>.+)$" {
        set $port 1935;
        set $prefix "http://10.5";
        set $target_url_a "$prefix.$a:$port/$suffix";
        set $target_url_b "$prefix.$b:$port/$suffix";
        add_header X-debug-message_a "$target_url_a"; #just testing   
        add_header X-debug-message_b "$target_url_b"; #just testing             
        #proxy_pass $target_url_a; #enable this one for real
        return 200; #just testing        
    }
> GET /9.157/7.134/live/playlist.m3u8 HTTP/1.1
...
> User-Agent: curl/7.43.0
> Accept: */*
>

< HTTP/1.1 200 OK
...
< Content-Length: 0
< Connection: keep-alive
< X-debug-message_a: http://10.5.9.157:1935/live/playlist.m3u8
< X-debug-message_b: http://10.5.7.134:1935/live/playlist.m3u8