简体   繁体   English

使用 Apache 的 ProxyPassMatch,我如何只传递我的 URL 的一部分?

[英]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.

相关问题 如何访问我的 Django 网站的 url 上的数据 - How do I reach a data that is on my Django website's url 如何调整我的 Apache Docker 配置以仅将一些 URL 路由到我的 Docker django 实例? - How do I adjust my Apache Docker config to only route some URLs to my Docker django instance? 如何使用apache设置django以便我的应用程序位于根URL? - How do I setup django with apache so that my appliction is at the root url? 如何将变量从一个视图传递到另一个视图并使用 Django 中最后一个视图的 URL 进行渲染? - How do I pass variables from one view to another and render with the last view's URL in Django? 如何将上下文名称传递到模板 html django 中的 url 调用中 - How do I pass a context name into a url call in my template html django 如何将django视图的URL设置为网站的根域? - How do I set my django view's URL to the root domain of my website? 如何在我的主页URL上使用allauth的身份验证? - How do I make allauth's authentication available on my homepage URL? 如何在我的 WSGI apache 上为 Django 执行多个进程? - How do I do multiple processes for Django, on my WSGI apache? 如何小写我的部分网址地址的第一个字母? - How do I lowercase the first letter of part of my urls address? 如何在我的 Url 中传递多个参数 - How can I pass in multiple parameters in my Url
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM