Matt Clark
Matt Clark

Reputation: 28639

Using httpd ProxyPass with DirectoryIndex

How can I use a ProxyPass and DirectoryIndex at the same time?

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

I however, am getting a 404 from the /static/ endpoint as it appears there is no default page trying to be loaded; this all works correctly if I hit

/index.html

Which routes me to 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?

Upvotes: 3

Views: 2669

Answers (2)

Daniel Ferradal
Daniel Ferradal

Reputation: 2900

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:

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.

Upvotes: 0

Daniel Scott
Daniel Scott

Reputation: 7971

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.

You should set the DirectoryIndex on your backend server. i.e. The one on port 8080.

Upvotes: 2

Related Questions