Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy to URI other than web root #149

Closed
mzagrabe opened this issue Sep 30, 2021 · 9 comments
Closed

proxy to URI other than web root #149

mzagrabe opened this issue Sep 30, 2021 · 9 comments
Labels

Comments

@mzagrabe
Copy link

Greetings,

Thank you for writing Polaris. I'm new to the project, but looking forward to being more experienced with it.

I've tried setting up polaris to run behind an apache gateway (reverse proxy) and have used #118 as a template for the apache configuration.

There are 3 different tests I am performing...
[a] browsing directly to the rust web server (port 5050)
[b] putting polaris behind a reverse proxy at the web root (/)
[c] putting polaris behind a reverse proxy at the location /polaris/

[a] works as expected (I'm excited!), but I'm getting less than perfect results with [b] and [c].

Polaris seems to be more happy with configuration that support [b] than [c]. But, I have got [c] to work with some hackery.

For instance, the following apache configuration appears to work out of the box:

Location: http://www.example.net/#/welcome

[0]
<VirtualHost *:80>
ProxyPass / http://127.0.0.1:5050/
ProxyPassReverse / http://127.0.0.1:5050/

but things do not work as expected when I change the proxy configurations to:

[1]
<VirtualHost *:80>
ProxyPass /polaris/ http://127.0.0.1:5050/
ProxyPassReverse /polaris/ http://127.0.0.1:5050/

for instance, the JS seems to be stuck unless I start apache in configuration [0] and then change to [1] and restart. That is if I modify [1] and restart apache, then I only get a blank screen when browsing to:

Location: http://www.example.net/polaris/#/welcome

So.. I set the configs to [0], then change it to [1] and I get the welcome page, but after entering the music location information and configuring a basic user there are other things that don't work quite right. For instance the directory images don't show up. When drilling down into a directory the left pane does not refresh. Here is a screenshot showing things:

image

Neither [b] nor [c] (with corresponding apache configs [0] and [1]) play music or correctly display directory contents in polaris.

This might be able to be solved with some apache mod_rewrite magic or proxy configuration, but I thought I'd bring the issue up here to see what you thought.

Thank you for your help!

@agersant
Copy link
Owner

agersant commented Oct 1, 2021

Hello! Apache configuration isn't something I'm very knowledgeable about so I don't have a great answer to give :(
One thing that could help troubleshooting is using the network tab in the browser's debug tools. I would be curious to see what the URLs for broken content (font icons, album art) look like VS URLs for content that works (JS source, API calls, etc.).

@mzagrabe
Copy link
Author

mzagrabe commented Oct 1, 2021

Hello!

Here is a screenshot of the network debugging for a proxy at the web root (/) that shows folder (directory) icon, but does not load the music when drilling down. You'll notice the 404 error.

image

And here is the corresponding screenshot of using the rust web server (port 5050) directly:

image

@mzagrabe
Copy link
Author

mzagrabe commented Oct 1, 2021

And here are the logs from running polaris with the -f switch.

The GETs from 127.0.0.1 are the proxied "session":

14:49:08 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 127.0.0.1:34028 "GET /api/initial_setup HTTP/1.1" 200 22 "http://zeus.z.net/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.000802
14:49:08 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 127.0.0.1:34028 "GET /api/preferences HTTP/1.1" 200 70 "http://zeus.z.net/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.000953
14:49:08 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 127.0.0.1:34028 "GET /api/browse/ HTTP/1.1" 200 112 "http://zeus.z.net/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.003241
14:49:08 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 127.0.0.1:34030 "GET /index.0b276229.css.map HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.000350
14:49:14 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 127.0.0.1:34032 "GET /api/browse/archive HTTP/1.1" 200 141468 "http://zeus.z.net/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.033133
14:49:17 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 127.0.0.1:34034 "GET /index.d9f7726e.js.map HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.000309

And these should be me browsing directly to the rust server (port 5050). Note that there were a couple of browsing events that occurred, so the following logs are a bit longer that the preceding logs:

14:54:05 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50074 "GET / HTTP/1.1" 200 446 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.000630
14:54:05 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50076 "GET /index.0eb5d501.css HTTP/1.1" 304 0 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.000365
14:54:05 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50078 "GET /index.d9f7726e.js HTTP/1.1" 304 0 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.000368
14:54:06 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50074 "GET /index.0b276229.css HTTP/1.1" 200 2738 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.227461
14:54:06 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50074 "GET /api/initial_setup HTTP/1.1" 200 22 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.000450
14:54:06 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50074 "GET /api/preferences HTTP/1.1" 200 70 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.001155
14:54:06 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50074 "GET /api/browse/ HTTP/1.1" 200 112 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.003184
14:54:06 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50076 "GET /hind-v10-latin-ext_latin-300.a86b0b03.woff2 HTTP/1.1" 200 20604 "http://zeus.z.net:5050/index.0eb5d501.css" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.227857
14:54:06 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50078 "GET /hind-v10-latin-ext_latin-600.41e6fe79.woff2 HTTP/1.1" 200 21584 "http://zeus.z.net:5050/index.0eb5d501.css" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.230717
14:54:06 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50074 "GET /material-icons-regular.49e147fe.woff2 HTTP/1.1" 200 44300 "http://zeus.z.net:5050/index.0eb5d501.css" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.237982
14:54:06 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50074 "GET /api/audio/archive%2F311%2F311%2Fall_mixed_up.ogg?auth_token=70eaDdEt4zRqmJ1utxFeoTfJOe8iezz3hKwJowp3ITDUjr1NpcPqXjpgDFJSZ5zFAorMfJWO3UDIxzmidHlTa0ZifRejGt3oTU2dCsBttH3uysASucL8 HTTP/1.1" 206 33723 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.002200
14:54:06 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50080 "GET /api/audio/archive%2F311%2F311%2Fall_mixed_up.ogg?auth_token=70eaDdEt4zRqmJ1utxFeoTfJOe8iezz3hKwJowp3ITDUjr1NpcPqXjpgDFJSZ5zFAorMfJWO3UDIxzmidHlTa0ZifRejGt3oTU2dCsBttH3uysASucL8 HTTP/1.1" 200 327680 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.233207
14:54:06 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50074 "GET /favicon.c84c16f1.png HTTP/1.1" 200 2166 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.015274
14:54:06 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50078 "GET /api/audio/archive%2F311%2F311%2Fall_mixed_up.ogg?auth_token=70eaDdEt4zRqmJ1utxFeoTfJOe8iezz3hKwJowp3ITDUjr1NpcPqXjpgDFJSZ5zFAorMfJWO3UDIxzmidHlTa0ZifRejGt3oTU2dCsBttH3uysASucL8 HTTP/1.1" 206 2393019 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.150376
14:54:19 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50082 "GET /api/initial_setup HTTP/1.1" 200 22 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.000857
14:54:19 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50082 "GET /api/preferences HTTP/1.1" 200 70 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.001173
14:54:19 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50084 "GET /api/browse/ HTTP/1.1" 200 112 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.002877
14:54:25 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50086 "GET /api/browse/archive HTTP/1.1" 200 141468 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.014118
14:54:27 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50086 "GET /api/browse/archive%2F10000_maniacs HTTP/1.1" 200 331 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.012270
14:55:03 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50090 "GET /api/initial_setup HTTP/1.1" 200 22 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.000848
14:55:03 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50090 "GET /api/preferences HTTP/1.1" 200 70 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.001104
14:55:03 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50090 "GET /api/browse/ HTTP/1.1" 200 112 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.003328
14:55:03 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50090 "GET /api/audio/archive%2F311%2F311%2Fall_mixed_up.ogg?auth_token=70eaDdEt4zRqmJ1utxFeoTfJOe8iezz3hKwJowp3ITDUjr1NpcPqXjpgDFJSZ5zFAorMfJWO3UDIxzmidHlTa0ZifRejGt3oTU2dCsBttH3uysASucL8 HTTP/1.1" 206 262144 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.013362
14:55:03 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50092 "GET /api/audio/archive%2F311%2F311%2Fall_mixed_up.ogg?auth_token=70eaDdEt4zRqmJ1utxFeoTfJOe8iezz3hKwJowp3ITDUjr1NpcPqXjpgDFJSZ5zFAorMfJWO3UDIxzmidHlTa0ZifRejGt3oTU2dCsBttH3uysASucL8 HTTP/1.1" 206 33723 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.000486
14:55:04 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50092 "GET /api/audio/archive%2F311%2F311%2Fall_mixed_up.ogg?auth_token=70eaDdEt4zRqmJ1utxFeoTfJOe8iezz3hKwJowp3ITDUjr1NpcPqXjpgDFJSZ5zFAorMfJWO3UDIxzmidHlTa0ZifRejGt3oTU2dCsBttH3uysASucL8 HTTP/1.1" 206 2294715 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.171173
14:55:07 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50092 "GET /api/browse/archive HTTP/1.1" 200 141468 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.014215
14:55:09 [INFO] [/home/z/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/middleware/logger.rs:337] 192.168.0.47:50092 "GET /api/browse/archive%2F10000_maniacs HTTP/1.1" 200 331 "http://zeus.z.net:5050/" "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0" 0.011972

@agersant
Copy link
Owner

agersant commented Oct 4, 2021

The failed requests don't even show up in the log so it's possible they weren't routed to the Polaris server at all. When you get a failed request in your Chrome debug tool, can you look at the content of the Headers tab? It would look like this:

image

I think the issue is either:

  1. Somehow the web client ends up requesting an incorrect URL (which the info above should validate)
  2. The Apache proxy gets tripped by the URL and does not route it to Polaris (not sure what to do with that)

@mzagrabe
Copy link
Author

mzagrabe commented Oct 4, 2021

Hi Antoine,

Some progress...

Looks like apache (by default) returns 404 for any URIs with encoded slashes:

http://httpd.apache.org/docs/2.4/mod/core.html#allowencodedslashes

Thus, this configuration works for reverse proxying polaris at the web root:

<VirtualHost *:80>
AllowEncodedSlashes NoDecode
ProxyPass / http://127.0.0.1:5050/
ProxyPassReverse / http://127.0.0.1:5050/
</VirtualHost *:80>

That being said, I'm still hitting issues with a reverse proxy setup at /polaris.

You can see the 200 for /polaris/, but then 404s after that:

192.168.0.47 - - [04/Oct/2021:11:59:32 -0500] "GET /polaris/ HTTP/1.1" 200 675 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36"
192.168.0.47 - - [04/Oct/2021:11:59:32 -0500] "GET /index.0b276229.css HTTP/1.1" 404 488 "http://zeus.z.net/polaris/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36"
192.168.0.47 - - [04/Oct/2021:11:59:32 -0500] "GET /index.0eb5d501.css HTTP/1.1" 404 488 "http://zeus.z.net/polaris/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36"
192.168.0.47 - - [04/Oct/2021:11:59:32 -0500] "GET /index.d9f7726e.js HTTP/1.1" 404 489 "http://zeus.z.net/polaris/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36"
192.168.0.47 - - [04/Oct/2021:11:59:32 -0500] "GET /favicon.c84c16f1.png HTTP/1.1" 404 488 "http://zeus.z.net/polaris/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36"

I'll keep digging on this end.

@mzagrabe
Copy link
Author

mzagrabe commented Oct 4, 2021

Hello,

I believe I have it solved...

I thought I had this apache module enabled, but I didn't:

https://httpd.apache.org/docs/2.4/mod/mod_proxy_html.html

So, after the following:

a2enmod proxy_html

The following config works:

<VirtualHost *:80>
AllowEncodedSlashes NoDecode
# Polaris streaming application
RewriteEngine On
RewriteRule ^/polaris$ /polaris/ [R]
ProxyPass /polaris/ http://127.0.0.1:5050/
ProxyPassReverse /polaris/ http://127.0.0.1:5050/

@mzagrabe
Copy link
Author

mzagrabe commented Oct 5, 2021

I'm still fighting trying to get /polaris/ to be a gateway for http://127.0.0.1:5050/

I'm still researching and seeking to get this working, but I thought I'd update the ticket with my current status of "not quite there".

So, if anyone has advice to offer, I'd love to hear it.

@mzagrabe
Copy link
Author

mzagrabe commented Oct 8, 2021

I spoke with folks on the apache users mailing list and the following apache configs are allowing me to reverse proxy polaris at example.com/polaris

`<VirtualHost *:80>
AllowEncodedSlashes NoDecode
RewriteEngine On
RewriteRule ^/polaris$ /polaris/ [R]

ProxyRequests Off
ProxyPass /polaris/ http://127.0.0.1:5050/
<Location /polaris/>
    ProxyPassReverse /
    RequestHeader Unset Accept-Encoding
    ProxyHTMLEnable On
    ProxyHTMLURLMap http://127.0.0.1:5050/ /polaris/
    ProxyHTMLURLMap / /polaris/
</Location>

`

Until things don't work, I'd say the above is my working configuration.

@agersant
Copy link
Owner

agersant commented Oct 9, 2021

Thank you for reporting back. I'm happy you got it working! 🎉

@agersant agersant closed this as completed Oct 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants