New user's registration have been closed due to high spamming and low trafic on this forum. Please contact forum admins directly if you need an account. Thanks !

Reverse proxy for Logitech Media Server

A collection of tips on howto tweak your Bubba.
Post Reply
Gordon
Posts: 1461
Joined: 10 Aug 2011, 03:18

Reverse proxy for Logitech Media Server

Post by Gordon »

Let me start by saying that this had me stumped for quite a while. Years in fact. The theory is simple: you tell apache to proxy '/lms' or whatever base name you want to give it to http://localhost:9000 and you're done. Alas that doesn't work and although it does show you some of the content of the LMS web UI it's mostly an empty page with nothing to click on.

The cause of this is that apache is unable to add your chosen prefix to each and every reference that the page makes to (mostly) static content like stylesheets, images and java include scripts. As a result your browser will request those files to be served from your regular webroot where of course these files do not exist.

The answer is: you need to create a separate vhost. One where you can proxy '/' in stead of needing to proxy '/app' and thus do not need to translate any included links.

The virtual host definition is quite simple:

Code: Select all

<VirtualHost *:80>
    ServerName squeezebox
    ServerAlias squeezebox.localdomain
    DocumentRoot /home/www
    ErrorLog logs/squeezebox_log
    CustomLog logs/squeezebox-access_log common

    <Proxy *>
        Order deny,allow
        Deny from all
        Deny from 192.168.10.1
        Allow from 192.168.10.0/24
    </Proxy>

    ProxyPreserveHost On
    ProxyRequests off

    ProxyPass / http://localhost:9000/
    ProxyPassReverse / http://localhost:9000/
</VirtualHost>
if you're running apache 2.3 or higher, the 'Proxy' part should read like this:

Code: Select all

    <Proxy *>
        <RequireAll>
            Require not ip 192.168.10.1
            Require ip 192.168.10.0/24
        </RequireAll>
    </Proxy>
Next you need to make sure that http://squeezebox resolves to your b3 address. To do that open /etc/hosts in your editor and add the name squeezebox (preferably with its full domain name - if you didn't set any just leave it) to the end of the line that holds your B3's address and name. e.g.:

Code: Select all

192.168.10.1    b3       b3.localdomain    squeezebox.localdomain
Next reload apache and restart dnsmasq

Code: Select all

/etc/init.d/apache2 reload
/etc/init.d/dnsmasq restart
Now you can point your browser to http://squeezebox and forget about that crazy number behind the colon.

Note: be aware that apache will take your first vhost definition (the one in the file that is on top when sorted by name) as your default host. Any request to the server that does not match a vhost's ServerName or ServerAlias directive will be served by the default host.
Gordon
Posts: 1461
Joined: 10 Aug 2011, 03:18

Re: Reverse proxy for Logitech Media Server

Post by Gordon »

As it turns out the above is incomplete for LMS. The reason is that Apache will generate an instant 404 on some of the URI's generated by LMS. Most specifically this happens with radio channel logos that are cached by LMS in several resized versions and include the original web location as an url-encoded string in the request.
example: wrote: http://squeezebox/imageproxy/http%3A%2F%2Fcdn-radiotime-logos.tunein.com%2Fs96203q.png/image_50x50_o
Consequently we need a custom 404 handler to redirect those requests correctly, which in turn means we need to set a document root and proxying needs to be conditional (because Apache should serve the 404 error document). The resulting thus becomes as follows (for apache >= 2.3:

Code: Select all

<VirtualHost *:80>
        ServerName squeezebox.localdomain
        ServerAlias squeezebox
        ErrorLog logs/squeezebox_log
        CustomLog logs/squeezebox-access_log common

        DocumentRoot /home/www
        ErrorDocument 404 /redir9000.php

        <Directory "/home/web/">
                AllowOverride None
                <RequireAll>
                        Require not ip 192.168.10.1
                        Require ip 192.168.10.0/24
                </RequireAll>
         </Directory>

        RewriteEngine on
        RewriteCond %{REMOTE_ADDR} !^192\.168\.10\.1$
        RewriteCond %{REMOTE_ADDR} ^192\.168\.10\.
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
        RewriteRule ^/(.*)$ http://%{HTTP_HOST}:9000/$1 [NE,P,L]
</VirtualHost>
And the content of /home/web/redir9000.php:

Code: Select all

<?php
    $redirect = "http://".$_SERVER['HTTP_HOST'].":9000".$_SERVER['REQUEST_URI'];
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: $redirect");
?>

Of course you should change localdomain, LAN IP range and web root to match your own setup.
Post Reply