spl0k / supysonic

Supysonic is a Python implementation of the Subsonic server API.
https://supysonic.readthedocs.io
GNU Affero General Public License v3.0
263 stars 58 forks source link

Be nice with reverse proxies #23

Open shammash opened 10 years ago

shammash commented 10 years ago

Please consider adding a middleware like http://flask.pocoo.org/snippets/35/ so supysonic can run below some path other than / .

Thank you.

knealmarc commented 8 years ago

Is this solved by running supysonic as WSGI app?

The application path is defined by the WSGIScriptAlias ... ... line, see the "As an Apache WSGI application" in the README.md for example config.

bjmgeek commented 7 years ago

It works for me as a wsgi app behind a reverse proxy.

Here's the log from my main server:

==> /var/log/apache2/example.com.access.log <==
2001:470:8:ec:: - - [27/Mar/2017:15:56:37 -0400] "GET /supysonic/rest/stream.view?u=bjmgeek&p=enc:XXXXXXXX&f=jsonp&v=1.8.0&c=Jamstash&id=XXXXXX&salt=5454 HTTP/1.1" 206 3789114 "http://www.jamstash.com/" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"

Here's the log from the reverse proxy:

==> /var/log/apache2/music.example.com.access.log <== 
50.164.119.132 - - [27/Mar/2017:15:56:37 -0400] "GET /rest/stream.view?u=bjmgeek&p=enc:XXXXXXXX&f=jsonp&v=1.8.0&c=Jamstash&id=XXXXXXXX&salt=5454 HTTP/1.1" 206 3789122 "http://www.jamstash.com/" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"

apache config for the reverse proxy:

<VirtualHost *:80>
        ServerName music.example.com
        CustomLog /var/log/apache2/music.example.com.access.log combined

        ProxyPass / http://example.com/supysonic/
        ProxyPassReverse / http://example.com/supysonic/
</VirtualHost>

apache config for main site /supysonic:

WSGIScriptAlias /supysonic /home/bjmgeek/public_html/programs/supysonic/cgi-bin/supysonic.wsgi 
<Directory /home/bjmgeek/public_html/programs/supysonic/cgi-bin> 
    WSGIApplicationGroup %{GLOBAL} 
    WSGIPassAuthorization On 
    Order deny,allow 
    Allow from all 
</Directory>

It's not perfect, http://music.example.com redirects to http://music.example.com// but it works fine with API calls.

bjmgeek commented 7 years ago

update: when I logged out, this broke, because I got an endlessly growing redirect loop. The culprit seems to be "GET /supysonic/supysonic/user/login?returnUrl=%2Fsupysonic%2Fsupysonic%2Fuser%2Flogin%3FreturnUrl%3D%252Fsupysonic%252Fsupysonic%252Fuser%252Flogin%253FreturnUrl%253D%25252Fsupysonic%25252Fsupysonic%25252Fuser%25252Flogin%25253FreturnUrl ad infinitum.

Alch-Emi commented 6 years ago

I'm not 100% sure this is what OP was looking for, but I believe that @knealmarc was right about being able to configure this using wsgi settings. I'm running uwsgi behind Caddy with supysonic mounted at /music, and I've yet to experience any problems, (including problems logging out). I'm running uwsgi with the options:

--mount="/music=/path/to/server.py" --manage-script-name --module main --callable app --http :5000

and the relevant block of my caddyfile is

proxy /music localhost:5000 {
     transparent
}

I can connect to https://myserver.com/music to get to the supysonic main page, and everything works fine from there.