简体   繁体   English

将 httpd ProxyPass 与 DirectoryIndex 一起使用

[英]Using httpd ProxyPass with DirectoryIndex

How can I use a ProxyPass and DirectoryIndex at the same time?如何同时使用ProxyPassDirectoryIndex

I have the following rule:我有以下规则:

# Index
DirectoryIndex index.html

# Service Endpoint
ProxyPass /endpointA http://127.0.0.1:wxyz/
ProxyPassReverse /endpointA http://127.0.0.1:wxyz/

# Root Endpoint
ProxyPass / http://127.0.0.1:8080/static/
ProxyPassReverse / http://127.0.0.1:8080/static/

The expected behavior is that when a user hits the machine at / , they should be served 127.0.0.1:8080/static/index.html预期的行为是,当用户在/处点击机器时,应该为他们提供127.0.0.1:8080/static/index.html

I however, am getting a 404 from the /static/ endpoint as it appears there is no default page trying to be loaded;但是,我从/static/端点收到 404,因为它似乎没有尝试加载默认页面; this all works correctly if I hit如果我击中,这一切正常

/index.html

Which routes me to 127.0.0.1:8080/static/index.html这将我路由到127.0.0.1:8080/static/index.html

How can I have a ProxyPass and a DirectoryIndex working at the same time, or some other combination of configuration, so that when a user simply hits / , they are routed to 127.0.0.1:8080/static/index.html and not just 127.0.0.1:8080/static ?如何让 ProxyPass 和 DirectoryIndex 同时工作,或其他一些配置组合,以便当用户简单地点击/ ,它们会被路由到127.0.0.1:8080/static/index.html而不仅仅是127.0.0.1:8080/static

The problem is that the DirectoryIndex won't be used because the server's already matched the ProxyPass /, and so it's already been passed to the other server.问题是 DirectoryIndex 不会被使用,因为服务器已经匹配了 ProxyPass /,所以它已经被传递到另一个服务器。

You should set the DirectoryIndex on your backend server.您应该在后端服务器上设置 DirectoryIndex。 ie The one on port 8080.即端口 8080 上的那个。

I have tested several ways and the only one who yielded the same result you seem to want for me as of now has seem to be using mod_rewrite as in:我已经测试了几种方法,到目前为止,唯一一种产生您似乎想要的相同结果的方法似乎正在使用 mod_rewrite,如下所示:

RewriteEngine on
RewriteRule ^/$ http://127.0.0.1:8080/static/index.html [P,L]

then you can add the rest:然后你可以添加其余的:

RewriteRule ^/(.+) http://127.0.0.1:8080/static/$1 [P,L]

This may be a rough way to do it.这可能是一种粗略的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM