[英]With Apache's ProxyPassMatch, how do I pass on only part of my URL?
I'm running Apache 2.4 with a Python 3 / Django 3 app, both in Docker containers.我在 Docker 容器中运行带有 Python 3 / Django 3 应用程序的 Apache 2.4。 If my Apache container gets a request with "/api", I would like to redirect that request to the Python container.如果我的 Apache 容器收到带有“/api”的请求,我想将该请求重定向到 Python 容器。 So if my Apache request is所以如果我的 Apache 请求是
http://localhost:9090/api/states/US
I would like to redirect to the Python container using the URL我想使用 URL 重定向到 Python 容器
http://web:8000/states/US
In my virtual host file I have在我的虚拟主机文件中,我有
<VirtualHost *:80>
ServerName directory.example.com
ProxyPassMatch ^/api http://web:8000/(.*)
ProxyPassReverse ^/api http://web:8000/(.*)
But when I make the request for "http://localhost:9090/api/states/US", I get this in my Docker logs但是当我请求“http://localhost:9090/api/states/US”时,我在我的 Docker 日志中得到了这个
maps-web-1 | Not Found: /(.*)/api/states/US
maps-apache-1 | 172.23.0.1 - - [30/Jun/2022:20:23:49 +0000] "GET /api/states/US HTTP/1.1" 404 6128
So evidently my ProxyPassMatch is not correct.所以显然我的 ProxyPassMatch 是不正确的。 How do I set that up properly?我该如何正确设置?
You have missed out quotes by the looks of it.从外观上看,您已经错过了报价。 Try something like尝试类似的东西
ProxyPassMatch "/api(.*)" "http://web:8000$1"
ProxyPassReverse "/api(.*)" "http://web:8000$1"
In the above the (.*) is a curved bracket selector that finds everything after /api and places it in the $1 position in the next string.上面的 (.*) 是一个弧形括号选择器,它查找 /api 之后的所有内容并将其放置在下一个字符串的 $1 位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.