Subsonic External Sharing Through Custom Domain

Tutorials, tips and tricks.

Moderator: moderators

Subsonic External Sharing Through Custom Domain

Postby sdct989 » Thu Apr 18, 2013 5:40 pm

I really enjoy Subsonic, but I was wondering if there was any way to setup sharing using my own domain rather than the one that I have created at subsonic.org? I would very much like to utilize the sharing option, but have it be from my own domain.

Also, even when I try to use my subsonic.org sub-domain for sharing, it seems to fail. I'm guessing that this is because I don't have Subsonic open on port 4040? Instead I have setup Subsonic to be proxy'd through Apache. So that means that the way that I access Subsonic from the internet is by going to https://www.mydomain.com/subsonic. This works for all of the apps that I use like Android and iOS applications, but this doesn't appear to work for sharing. Is there any way to enable sharing for Subsonic servers that don't open their own custom http port?
User avatar
sdct989
 
Posts: 30
Joined: Thu Jan 31, 2013 4:11 am

Re: Subsonic External Sharing Through Custom Domain

Postby sdct989 » Wed May 01, 2013 6:31 pm

I never heard back on this post from any official source, but I was able to find a work around for myself and resolve the problem that I was seeing.

Basically, the problem was that when I used my subsonic.org sub-domain it was still forwarding back to my IP address on port 4040. I'm guessing that this comes from the subsonic.sh file's configuration property: SUBSONIC_PORT. However, I don't expose port 4040 to the internet, instead I currently have Subsonic proxy'd through an Apache web server so that I can use ports 80 and 443 from the internet. Then I access Subsonic via something like this: https://domain.com/subsonic rather than https://domain.com:4040. Even though Subsonic is still running on port 4040, from outside the firewall it appears as if port 4040 is not open. I do this this for many services and not just Subsonic.

However, I noticed that in playing with the share URL that I was given after the redirect from my subsonic.org subdomain, if I just removed the :4040 from the URL the music file played just fine. This told me that the sharing mechanism works fine, it's just the redirect mechanism that was broken. And since I would rather have it share from my own subdomain anyway, this was just fine for me. However, it would be a pain to have to keep changing the url every time I wanted to share music with a friend, so instead I hacked some of the JSP pages included in the subsonic.war file so that it would present me with the correct sharing URL from my domain without having to go to subsonic.org for a redirect.

I figured that I would post my solution here so that if anyone else had an Apache proxy configuration like I do, they could also benefit from this fix. I should mention that this is not a very elegant fix, the best fix would be for someone on the Subsonic team to add configuration items in the subsonic.sh script so that we could pass these parameters to the Subsonic runtime. The following steps are a bit advanced, so if you feel uncomfortable with the command line or troubleshooting you'll probably want to steer clear. But in lui of that, this solution will definitely work.

Here are the instructions (I wrote them for *nix based systems, Windows users will have to adapt them):
  1. Download the attached patch file and open it in a text editor
  2. Find and replace any instances of "<http(s)://your_domain_and_path_here>" (without the quotes) (there should be only two instances of it) with your domain. Something similar to "https://domain.com/subsonic" or "http://123.123.123.123/subsonic" if you would prefer to use your IP address instead.
  3. Log in to the computer with your subsonic instance running on it (if you're not there already) and kill the subsonic service
  4. Find your Subsonic installation folder and run the following commands:
    Code: Select all
    cp subsonic.war /tmp
    mkdir /tmp/subsonic
    cd /tmp/subsonic
    jar -xvf ../subsonic.war
  5. Upload the patch file you modified to wherever you're hosting subsonic (if you're not already there) and place it in the /tmp directory
  6. Run the following commands:
    Code: Select all
    cd /tmp/subsonic
    patch -p1 < ../subsonic-sharing-domain.patch
    jar -cf ../subsonic.war.new *
  7. Now change directory to your subsonic installation and run the following commands:
    Code: Select all
    mv subsonic.war subsonic.war.old
    mv /tmp/subsonic.war.new subsonic.war
    rm -rf /tmp/subsonic/
    rm /tmp/subsonic.war /tmp/subsonic-sharing-domain.patch
  8. If you were running any of these commands as something other than the user that runs subsonic, make sure that you chown the subsonic.war file back to the original user with something like "chown subsonic:subsonic subsonic.war"
  9. Start subsonic again
User avatar
sdct989
 
Posts: 30
Joined: Thu Jan 31, 2013 4:11 am

Re: Subsonic External Sharing Through Custom Domain

Postby Tearstar » Sat May 04, 2013 8:44 am

Thank you for the patch, I too run my SS through Apache with a reverse proxy to my domain, so I am having the same issue with the share feature. I will input these changes tomorrow and let you know if I have any problems or questions.
Tearstar
 
Posts: 9
Joined: Wed May 01, 2013 6:02 pm

Re: Subsonic External Sharing Through Custom Domain

Postby sdct989 » Sat May 04, 2013 4:43 pm

I figured I wouldn't be the only one with this problem.

I would definitely appreciate more people giving it a run through so I can refine the instructions a bit. So let me know if you have any problems or if anything is hard to understand.

As a side note, I've tested this against 3.7 and 3.8. I'm not sure how well it works on earlier versions.

Also, someone pointed out that in order to be able to use the jar command you'll have to have a Java JDK and not just a JRE. I believe that you can also just use the zip command to inflate the subsonic archive instead of jar, but I haven't gotten a chance to test this yet.

Sent from my Galaxy Nexus using Tapatalk 2
User avatar
sdct989
 
Posts: 30
Joined: Thu Jan 31, 2013 4:11 am

Re: Subsonic External Sharing Through Custom Domain

Postby Tearstar » Sun May 05, 2013 4:42 pm

Well I have to admit, I didn't go through the patch instructions . . . what I did was opened your patch file in my text editor, and opened the two needed files from my subsonic folder in my text editor. I made the changes manually cause I wanted to see what was being done and it works like a charm ( and I'm using 4.8 )

Thanks alot, great patch!
Tearstar
 
Posts: 9
Joined: Wed May 01, 2013 6:02 pm

Re: Subsonic External Sharing Through Custom Domain

Postby sdct989 » Sun May 05, 2013 8:37 pm

I'm glad that it helped! I totally understand wanting to know the changes it's making. :-)

Sent from my Galaxy Nexus using Tapatalk 2
User avatar
sdct989
 
Posts: 30
Joined: Thu Jan 31, 2013 4:11 am

Re: Subsonic External Sharing Through Custom Domain

Postby Tearstar » Mon May 06, 2013 3:43 am

Out of curiosity . . . do you know how, or can you help me to figure out how to add the share function to the shared page?

I have my guests as being allowed to share, but I wanted to provide the facebook, google and twitter buttons to the shared page.

If you look at this page http://eradio.sytes.net/share/khZhC

I'd like to have the buttons (no text) below the title
Tearstar
 
Posts: 9
Joined: Wed May 01, 2013 6:02 pm

Re: Subsonic External Sharing Through Custom Domain

Postby sdct989 » Mon May 06, 2013 4:18 am

You'll want to look at the externalPlayer.jsp view.

I'm not entirely sure that I understand exactly what you're trying to do, but if you're just trying to place links under the page title to the current shared page, you should be able to do that pretty easily. For the URL of the currently streaming page you can just use the JSP statement:
Code: Select all
request.getRequestURL().toString()

Although you may have to bundle your own icons for the different social media networks as well. I'm not sure if they come bundled somewhere in Subsonic already.

If you're trying to link each individual song that is playing in JWPlayer by placing icons for the social networks under the title of each song, then I'm pretty sure that you won't be able to do that as that whole player section is just one big Flash object. Although you could try looking at their documentation to see if they provide some sort of way to share individual tracks. Maybe something like this? http://www.longtailvideo.com/support/jw-player/28857/social-sharing-options
User avatar
sdct989
 
Posts: 30
Joined: Thu Jan 31, 2013 4:11 am

Re: Subsonic External Sharing Through Custom Domain

Postby Tearstar » Tue Jun 11, 2013 11:23 am

I am just trying to put the same share links that are on the albums page, to the page that is created when it is shared, minus the actual "Share button" cause I don't want 1000+ different shared links in the system for the same album, and minus the "Play All", "Play Random","Download", "Edit Tags", etc part . . .

Just the ratings, the share links and the "Played 0 times"

Image
Tearstar
 
Posts: 9
Joined: Wed May 01, 2013 6:02 pm

Re: Subsonic External Sharing Through Custom Domain

Postby cowieson » Tue Aug 20, 2013 4:40 pm

I happened upon your post when searching for an Apache reverse proxy configuration suitable for use with subsonic - I hope it's not a pain of me to ask you to provide yours here if at all possible (sorry for hijacking the thread on that front!)? I'd very much appreciate it! :D
User avatar
cowieson
 
Posts: 8
Joined: Fri Feb 03, 2012 11:57 am

Re: Subsonic External Sharing Through Custom Domain

Postby sdct989 » Fri Aug 23, 2013 3:12 pm

Sorry it took me a while to respond. You should find Apache rewrite configuration pretty easy to navigate. The documentation that Apache has online is all pretty concise and to the point. And again, it depends on what you're trying to do, but to get you started I don't mind giving mine as an example. Here is an abbreviated version of my config:

Code: Select all
<VirtualHost _default_:443>
    RewriteEngine on

    SSLProxyEngine on

    RewriteCond %{REQUEST_URI} ^/+subsonic.*
    RewriteRule ^/(.*)$ http://127.0.0.1:4040/$1 [P,L]
    ProxyPassReverse  / http://127.0.0.1:4040/
</VirtualHost>


The above, assuming that you do the rest of the SSL configuration in your vhost will provide an SSL reverse proxy for your subsonic instance. In this way, if I go to https://www.mydomain.com/subsonic it will effectively get rewritten to localhost on port 4040 and the user's browser will be none the wiser.

Cheers!
User avatar
sdct989
 
Posts: 30
Joined: Thu Jan 31, 2013 4:11 am

Re: Subsonic External Sharing Through Custom Domain

Postby cowieson » Fri Aug 23, 2013 4:26 pm

Fantastic, thanks for taking the time to do that, I appreciate it. Looks like exactly what I've been trying to implement, with one small alteration;
I run my subsonic instance at the moment via a subdomain (ie https://subsonic.mydomain.com rather than https://mydomain.com/subsonic) - would I be correct in my assumption that I could quite possibly alter the line

Code: Select all
    RewriteCond %{REQUEST_URI} ^/+subsonic.*


to regex around my subdomain rather than this appended /subsonic string, and it would work in the same fashion?

EDIT: In fact, looking at the syntax, would I not actually remove the
Code: Select all
^/+subsonic.*


part of the above line, and add a ServerName entry under the VirtualHost to achieve what I need?
User avatar
cowieson
 
Posts: 8
Joined: Fri Feb 03, 2012 11:57 am

Re: Subsonic External Sharing Through Custom Domain

Postby sdct989 » Fri Aug 23, 2013 8:53 pm

Yeah, since your vhost is already controlled by your ServerName declaration inside the vhost, so I don't think that you need any conditions at all. I believe that you can just remove the RewriteCond line altogether and just go straight into the RewriteRule statement.
User avatar
sdct989
 
Posts: 30
Joined: Thu Jan 31, 2013 4:11 am

Re: Subsonic External Sharing Through Custom Domain

Postby cowieson » Tue Sep 17, 2013 4:28 pm

I'm not sure if anyone else will end up happening upon this post and whether or not my reverse proxy config may help, but here it is regardless (since that's the reason I came here in the first place!);

Code: Select all
<VirtualHost *:80>
# This section essentially forwards any non-SSL requests to SSL on port 443
    ServerName subsonic.mydomain.com
        RewriteEngine on
        ReWriteCond %{SERVER_PORT} !^443$
        RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</VirtualHost>

<VirtualHost *:443>
# This section does the actual reverse-proxying
    ServerAlias subsonic.mydomain.com
    ProxyPreserveHost on

# Important - this is necessary to allow requests to the root (nothing after the URL)   
    <location />
          allow from all
    </location>

# Reverse proxy config itself
    SSLProxyEngine On
   ProxyPass / http://localhost:4040/
    ProxyPassReverse / http://localhost:4040/

# SSL configuration for the web server to provide SSL to the reverse proxy session   
  SSLEngine on
  SSLProtocol all
  SSLCertificateFile "/path/to/cert"
  SSLCertificateKeyFile "/path/to/key" 
</VirtualHost>


Couple of things to note here; in my opinion, this is a cleaner way of doing the config for a reverse proxy - all requests, including those via regular HTTP, are properly forwarded preserving the host header and requested URL to the correct internal port, via SSL. It's important to note (as it's not necessarily intuitive) that subsonic must be running without SSL switched on internally; the web server handles the SSL in the process of reverse-proxying.

As an aside, I also implemented your patch to the share buttons, sdct989 - works a treat! Thanks again for the help, much appreciated.

Best,
cowieson
User avatar
cowieson
 
Posts: 8
Joined: Fri Feb 03, 2012 11:57 am

Re: Subsonic External Sharing Through Custom Domain

Postby sdct989 » Mon Oct 14, 2013 10:06 pm

Thanks for the addition cowieson! Very helpful!
User avatar
sdct989
 
Posts: 30
Joined: Thu Jan 31, 2013 4:11 am

Next

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests