3

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?

Matt Clark
  • 27,671
  • 19
  • 68
  • 123

2 Answers2

2

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.

Daniel Scott
  • 7,418
  • 5
  • 39
  • 58
0

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.

Daniel Ferradal
  • 2,727
  • 1
  • 13
  • 19
  • This does not answer the question. The user *wants* index.html to be proxied. – Daniel Scott Oct 19 '16 at 07:39
  • wops, you are completely right, I misread, allow me to fix it. – Daniel Ferradal Oct 19 '16 at 07:44
  • btw, I also support @DanielScott answer in which he tells you to use such redirects or index references in the backend itself, since you are relinquising / to the backend anyways. The only way I've found to control that from the frontend in this case is mod_rewrite, or at least in my tests, it is the only thing that takes precedence over proxypass – Daniel Ferradal Oct 19 '16 at 08:54