pimusicbox / mopidy-musicbox-webclient

Web Client for Mopidy Music Server and the Pi MusicBox
https://www.pimusicbox.com
Apache License 2.0
398 stars 106 forks source link

Webclient broken if placed behind reverse proxy #65

Closed andrenarchy closed 9 years ago

andrenarchy commented 9 years ago

In my setup, the mopidy server is made available through a reverse proxy (nginx) such that the mopidy root is available under https://domain/mopidy, i.e., the web clients are available as

The webclient fails to start up because it looks for https://domain/mopidy/mopidy.min.js while it should load https://domain/mopidy/mopidy/mopidy.min.js.

The fix is to load the js file through the relative path ../mopidy/mopidy.min.js instead of /mopidy/mopidy.min.js. I'll prepare a PR in a second.

jodal commented 9 years ago

IMHO, it is the responsibility of the proxy server to rewrite any paths in the response from the inner server to match the URL layout used by the proxy.

For an example config, see http://serverfault.com/a/379679.

andrenarchy commented 9 years ago

Exactly this configuration is used. However, the proxy server cannot fix absolute paths in the HTML code, see http://serverfault.com/a/359373.

kingosticks commented 9 years ago

This will be fixed in the next release.

lukasmrtvy commented 9 years ago

+1

ETA to 2.0.1? Thanks

kingosticks commented 9 years ago

The JS fix is in v2.0.0. If you are still having problems then it's something else.

lukasmrtvy commented 9 years ago

I have tried this: ProxyPass /musicbox_webclient/ http://localhost:6680/musicbox_webclient/ ProxyPassReverse /musicbox_webclient/ http://localhost:6680/musicbox_webclient/

well, it is not working, web page shows up, but nothing is working, expect settings button, which redirects to https://localhost/settings/

Do you have a configuration for Apache? I only found nginx. Thanks

kingosticks commented 9 years ago

if the page is displayed but nothing works then it sounds like it's specifically a websocket issue. I cant speculate what is wrong without seeing the entire nginx config. You also need to ensure you are running a new enough version of nginx.

I only have what is at https://github.com/pimusicbox/pimusicbox/pull/244

lukasmrtvy commented 9 years ago

Found solution for apache2.4 Just make you sure, that you have proxy_wstunnel installed (a2enmod proxy_wstunnel)

<VirtualHost *:8080>

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
<Proxy *>
Allow from all
</Proxy>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

ProxyRequests On
ProxyPass /musicbox_webclient/ http://localhost:6680/musicbox_webclient/
ProxyPassReverse /musicbox_webclient/ http://localhost:6680/musicbox_webclient/

ProxyPass /mopidy/ ws://localhost:6680/mopidy/
ProxyPassReverse /mopidy/ ws://localhost:6680/mopidy/

ProxyPass /mopidy/ http://localhost:6680/mopidy/
ProxyPassReverse /mopidy/ http://localhost:6680/mopidy/

</VirtualHost>
lukasmrtvy commented 9 years ago

Seems it doesnt work for proxied SSL connection

Chrome: Mixed Content: The page at 'https://10.0.0.47:8070/musicbox_webclient/index.html' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://10.0.0.47:8070/mopidy/ws/'. This request has been blocked; this endpoint must be available over WSS.

It is hardcoded (ws://), or what?

EDIT: I just found it in web.py. I would be great, if i may a choose ws or wss connection, Thanks

kingosticks commented 9 years ago

Does Mopidy even support secure websockets?

adamcik commented 9 years ago

If you put it behind a webserver that terminates the SSL then sure. Directly, no, though tornado does, but we don't configure it for that as it's a lot more sane to have something in front handling the private keys etc.

lukasmrtvy commented 9 years ago

https://github.com/mopidy/mopidy/issues/950

yonailo commented 9 years ago

I have tried the Apache2 solution from @muhahacz in the current 2.0.0 version but it does not work quite well for me.

The websocket's addresse gets rewritten to ws://my_domain_name:6680/mopidy/ws/.

The port 6680 is not accesible in my setup, and some 3G/4G mobile operators will block it even if I decided to open it.

I dont quite understand why the port is still there after having used the proxy_wstunnel configuration. Is it normal or should I add something to the Apache conf to have it rewritten to :80 ?

kingosticks commented 9 years ago

I can't help you with the apache config but have you tried the development branch? There are already settings there you can use for specifying a specific websocket host and port. However, I don't recall if that extends to the protocol. If not, we can fix that. On 24 Aug 2015 08:58, "yonailo" notifications@github.com wrote:

I have tried the Apache2 solution from @muhahacz https://github.com/muhahacz in the current 2.0.0 version but it does not work quite well for me.

The websocket's addresse gets rewritten to ws://:6680/mopidy/ws/.

The port 6680 is not accesible in my setup, and some 3G/4G mobile operators will block it even if I decided to open it.

I dont quite understand why the port is still there after having used the proxy_wstunnel configuration. Is it normal or should I add something to the Apache conf to have rewritten to :80 ?

— Reply to this email directly or view it on GitHub https://github.com/pimusicbox/mopidy-musicbox-webclient/issues/65#issuecomment-134082209 .

lukasmrtvy commented 9 years ago

@kingosticks still, you have to configure it like this https://github.com/andrenarchy/mopidy.js/commit/1e5ebe6059c44d02dae2fa88e7a6b577d5c2b77e (except this is in js) If the page was loaded via HTTPS, the websocket should also connect via HTTPS

Even in dev branch you have ws:// hardlinked. https://github.com/pimusicbox/mopidy-musicbox-webclient/blob/develop/mopidy_musicbox_webclient/web.py

yonailo commented 9 years ago

Thank you @kingosticks, I have not tried the development branch I prefer waiting to the official 2.0.1 release :)

kingosticks commented 9 years ago

So https://github.com/pimusicbox/mopidy-musicbox-webclient/commit/d211b92447e25f28e7f9af1e89310b74592479cf should help if you are using the websocket_host/websocket_port config settings.