我想通过捕获正则表达式组作为URI。
配置:Nginx的动态代理
location ~ /proxy/(.*?)$ {
proxy_pass http://$1;
}
需要:
http://127.0.0.1:9999/proxy/example.com/test/asd.html
应代理通行证:
http://example.com/test/asd.html
结果:
> curl http://127.0.0.1:9999/proxy/example.com/test/asd.html
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
错误日志是空的。
我在这里错过了什么?由于
很好的东西,这是我必须为正则表达式做的事情。我把你的输入字符串,并尝试与JS正则表达式let str =“http://127.0.0.1:9999/proxy/example.com/test/asd.html”; let result = str.match(/ proxy \ /(。*)$ /); console.log(result [1]); ==> example.com/test/asd.html让你无论是越狱“/”就像我得到example.com/test/asd.html或捕获它在D组,并使用代理服务器之后proxy_pass HTTP:/ $ 1; ==>注只有一个斜线 – JBone
看的以下代码块的工作。我粘贴在回答块显示代码清楚... – JBone