I have seen How to handle relative urls correctly with a reverse proxy - however I have great troubles understanding this (and applying it to my problem), hope someone can help.
Let's say that I have Ubuntu 20.04 as a server OS on my server, example.com
.
Then, I install https://github.com/hartwork/jawanndenn on the server, and run it - this application by default runs on port 8080; and I can confirm that it runs on the server itself, by running:
wget -O- http://127.0.0.1:8080
So far, so good. Now, what I would like, is that: instead of accessing https://example.com:8080
to access this application, I'd like like to access https://example.com/jaw
- where I'd usually call /jaw
a "subdirectory", but it is maybe more accurately a relative URL. In other words, if I understand the terminology correctly, https://example.com/jaw
would reverse proxy to https://example.com:8080
.
So, I've tried doing this, within the <VirtualHost *:443>
definition in my .conf
file:
<Location /jaw>
Options -Multiviews -Indexes
RewriteEngine On
ProxyPass http://127.0.0.1:8080
ProxyPassReverse http://127.0.0.1:8080
SetOutputFilter proxy-html
ProxyHTMLURLMap http://127.0.0.1:8080
</Location>
RewriteRule ^/jaw$ /jaw/ [R]
This works - in the sense that, the starting page of the application is loaded; but a whole ton of resources (.css, .js) cannot be loaded; opening the console in my browser, I can see a bunch of 404'd requests for:
https://example.com/static/3rdparty/jquery-3.5.1/jquery-3.5.1.min.js
https://example.com/static/3rdparty/roboto-20/css/roboto.css
...
So, my guess is, there are some .js files or similar, that simply want to load /static/...
-> and if called from the "port" address, they'd map to http://127.0.0.1:8080/static/...
and all would be fine; but now, since we're proxied:
- browser requests
https://example.com/jaw
- Apache gets that, forwards it to
https://example.com:8080
, where the application listens - Application sends back files (.js), that have links in the form
/static/...
- Once those arrive back in the browser, they are interpreted as
https://example.com/static/...
- before being used as requests for the server, which then cannot find them
I've also tried getting rid of the entire <Location>
snippet above, and just using this in the <VirtualHost *:443>
node:
ProxyPass /jaw/ http://127.0.0.1:6789/
ProxyPassReverse /jaw/ http://127.0.0.1:6789/
Exactly the same happens as previously - first page gets loaded, all the other resources apparently refger to /static/...
and they all 404.
Finally, I got rid of the above statements too, and used this:
ProxyPass /jaw/ http://127.0.0.1:8080
ProxyHTMLURLMap http://127.0.0.1:8080 /jaw
<Location /jaw/>
ProxyPassReverse /
ProxyPassReverse http://127.0.0.1:8080
ProxyHTMLEnable On
ProxyHTMLURLMap / /jaw/
</Location>
This has the exact same behavior - first page loads, resources fail - except resources are now listed in browser console as:
https://example.com/jaw/static/3rdparty/jquery-3.5.1/jquery-3.5.1.min.js
https://example.com/jaw/static/3rdparty/roboto-20/css/roboto.css
...
... and they fail with 502 Proxy Error. So some rewrite happened, but something is not right still.
So my question is - how can I say to Apache, to proxy everything from the application on 127.0.0.1:8080, to something that appears as a "subdirectory" (relative URL? here /jaw
)?
Edit: turns out, the 502 Proxy Error was due to:
AH00898: DNS lookup failure for: 127.0.0.1:6789static returned by /poll/static/js/html.js
... so clearly a slash is missing; so it ended up that this:
ProxyPass /jaw/ http://127.0.0.1:8080/
ProxyHTMLURLMap http://127.0.0.1:8080/ /jaw/
<Location /jaw/>
ProxyPassReverse /
ProxyPassReverse http://127.0.0.1:8080/
ProxyHTMLEnable On
ProxyHTMLURLMap / /jaw/
</Location>
... actually does work - for the most part (the /static
resources); but then, there is a call to /data
that does not get handled by this ... So it's still an open question (for me) how to proxy "everything"