![Nginx 代理将每个斜杠部分放入一个变量中](https://linux22.com/image/784807/Nginx%20%E4%BB%A3%E7%90%86%E5%B0%86%E6%AF%8F%E4%B8%AA%E6%96%9C%E6%9D%A0%E9%83%A8%E5%88%86%E6%94%BE%E5%85%A5%E4%B8%80%E4%B8%AA%E5%8F%98%E9%87%8F%E4%B8%AD.png)
我怎样才能将 URL 的每个斜线部分放入变量中以写入代理 URL?
例子:
https://example.com/part1/part2 或者 https://example.com/sub/8080
然后
proxy_pass http://$part1.example.com:$part2;
答案1
像这样:
location ~* /(.+)/(.+)$ {
set $hostpart $1;
set $urlpart $2;
proxy_pass http://$hostpart.example.com/$urlpart break;
}