ads

This tutorial is going to show you how to install Subsonic media server on Ubuntu 16.04 and how to set up a reverse proxy for Subsonic using Nginx or Apache.

Subsonic is a free, web-based media streamer written in Java, available for Linux, MacOS and Windows. With Subsonic, you can stream your music from home computer or any public-facing computer and listen to your music from anywhere with a web browser. So you don’t have to sync your music with a file sync application like resilio sync or Syncthing.

subsonic ubuntu install

Subsonic features

  • Supports MP3, OGG, AAC and any other audio or video format that streams over HTTP.
  • Works with any network-enabled media player, such as Winamp, iTunes, XMMS, VLC, MusicMatch and Windows Media Player
  • album art display, on-the-fly playlists, on-the-fly transcoding
  • Mobile App for Android, iPhone, Windows Phone and desktop app for Mac, Windows and Chrome. The Android app supports offline playback.
  • Listen to podcasts, assign ratings, add comments, and create playlists.
  • Share you music with friends and family.
  • Stream Videos (premium feature)
  • and more

Note that Subsonic is closed-source since version 6.0.

How to Install Subsonic Media Server on Ubuntu 16.04

Subsonic media server is written in Java, so you need to install Java runtime. You can install openjdk 8 with the following command.

sudo apt install openjdk-8-jre

Subsonic also works with Oracle Java 8 which can be easily installed.  Next, download Subsonic deb package.

wget https://s3-eu-west-1.amazonaws.com/subsonic-public/download/subsonic-6.0.deb

Install it with dpkg.

sudo dpkg -i subsonic-6.0.deb

Once it’s installed, the Subsonic daemon will automatically start.

systemctl status subsonic

Sample output:

● subsonic.service - LSB: Subsonic daemon
   Loaded: loaded (/etc/init.d/subsonic; bad; vendor preset: enabled)
   Active: active (running) since Fri 2017-03-24 08:03:27 EDT; 7min ago
     Docs: man:systemd-sysv-generator(8)
   CGroup: /system.slice/subsonic.service
           └─3316 java -Xmx150m -Dsubsonic.home=/var/subsonic -Dsubsonic.host=0

If it’s not running, then you can manually start it with

sudo systemctl start subsonic

And enable auto start at system boot time.

sudo systemctl enable subsonic

By default subsonic listens on 0.0.0.0:4040,which means it accepts requests from local network and the Internet.

If you installed Subsonic on a local Ubuntu computer, then type in the following address in browser to visit Subsonic web interface.

http://localhost:4040

If you installed Subsonic on an Internet-facing Ubuntu server, then type in the following address in browser to visit Subsonic web interface.

http://your-server-ip:4040

subsonic ubuntu 16.04

Please note that if you install Subsonic media server on a home server and you want to access it from outside network, then you will need to configure port forwarding in your router.

The default username and password are admin. After login you should go to Settings > Users to change the admin password. Also add media folders in the settings page.

subsonic media server

Changing User

By default the Subsonic process is run as the root user. For security reason you should change it to a normal user, which is done by editing the /etc/default/subsonic file.

sudo nano /etc/default/subsonic

Find the following line:

SUBSONIC_USER=root

Change root to your own user account like linuxbabe.

SUBSONIC_USER=linuxbabe

Save and close the file. Then restart subsonic daemon for the change to take effect.

sudo systemctl restart subsonic

Setting up Nginx Reverse Proxy for Subsonic

If you want to use a domain name for Subsonic web interface, then you can set up Nginx reverse proxy. Install Nginx on Ubuntu 16.04 using the command below.

sudo apt install nginx

Then create a server block file for proxy.

sudo nano /etc/nginx/conf.d/subsonic-proxy.conf

Put the following text into the file. Replace subsonic.your-domain.com with your own domain name. The location {…} block will make Nginx proxy requests to Subsonic daemon. Don’t forget to set A record for the sub domain.

server {
        listen 80;
        server_name subsonic.your-domain.com;

        location / {
                proxy_pass http://127.0.0.1:4040;
                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
        }
}

Save and close the file. Then test Nginx configuration.

sudo nginx -t

If the test is successful, then reload Nginx for the new configuration to take effect.

sudo systemctl reload nginx

Now subsonic media server is put behind Nginx and you can access Subsonic web UI using a domain name.

Enabling HTTPS with Nginx

To enable HTTPS secure connection, you can obtain and install a free TLS/SSL certificate from Let’s Encrypt. Install Let’s Encrypt (certbot) client with:

sudo apt install letsencrypt

Create a directory for Let’s Encrypt verification.

sudo mkdir /var/www/subsonic

Set www-data (Nginx user) as the owner of this directory.

sudo chown www-data:www-data /var/www/subsonic -R

Add the following directive in /etc/nginx/conf.d/subsonic-proxy.conf file.

location ~ /.well-known/acme-challenge {
        root /var/www/subsonic/;
        allow all;
}

Save and close the file. Reload Nginx for the changes to take effect.

sudo systemctl reload nginx

Then issue the following command to obtain certificate using the the webroot plugin. Replace red text with your actual data.

sudo letsencrypt certonly --webroot --agree-tos --email your-email-address -d subsonic.your-domain.com -w /var/www/subsonic/

Within a few seconds, you should see a congrats message like below which means the certificate is successfully obtained.

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at
   /etc/letsencrypt/live/subsonic.your-domain.com/fullchain.pem. Your cert
   will expire on 2017-06-23. To obtain a new version of the
   certificate in the future, simply run Let's Encrypt again.
 - If you like Let's Encrypt, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Next, let’s install the TLS/SSL certificate in Nginx. Open /etc/nginx/conf.d/subsonic-proxy.conf again.

sudo nano /etc/nginx/conf.d/subsonic-proxy.conf

hange the content of this file to the following. Replace subsonic.your-domain.com with your real domain name.

server {
        listen 80;
        server_name subsonic.your-domain.com;
        return 301 https://$server_name$request_uri;
}
server {
        listen 443 ssl http2;
        server_name subsonic.your-domain.com;

        ssl_protocols TLSv1.1 TLSv1.2;
        ssl_certificate /etc/letsencrypt/live/subsonic.your-domain.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/subsonic.your-domain.com/privkey.pem;

        location / {
                proxy_pass http://127.0.0.1:4040;
                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_redirect http:// https://;
        }

        location ~ /.well-known/acme-challenge {
             root /var/www/subsonic/;
             allow all;
        }
}

The directive proxy_redirect http:// https://; is needed to properly display Subsonic settings pages. Save and close the file. Test Nginx configuration and reload.

sudo nginx -t

sudo systemctl reload nginx

Go to your Subsonic media server Web interface again, you will find HTTP connection is automatically redirected to HTTPS secure connection.

Setting up Apache Reverse Proxy

If you prefer Apache, then install it with:

sudo apt install apache2

To use Apache as a reverse proxy, we need to enable the proxy modules.

sudo a2enmod proxy proxy_http

Then create a virtual host file for Subsonic media server.

sudo nano /etc/apache2/sites-available/subsonic-proxy.conf

Put the following configurations into the file. Replace subsonic.your-domain.com with your actual domain name.

<VirtualHost *:80>
   ServerName subsonic.your-domain.com
   ErrorDocument 404 /404.html
   DocumentRoot /var/www
   ProxyPass / http://localhost:4040/
   ProxyPassReverse / http://localhost:4040/
   Header always unset X-Frame-Options
</VirtualHost>

Save and close the file. Then enable this virtual host.

sudo a2ensite subsonic-proxy.conf

Restart Apache

sudo systemctl restart apache2

Now you can access Subsonic web UI using a domain name.

Enabling HTTPS with Apache

To enable HTTPS secure connection, you can obtain and install a free TLS/SSL certificate from Let’s Encrypt. Install Let’s Encrypt (certbot) client with:

sudo apt install letsencrypt python-letsencrypt-apache

Then obtain and install a certificate using the apache plugin.

sudo letsencrypt --apache -d subsonic.your-domain.com

You will be asked whether you want to allow plain HTTP protocol. It’s recommended to choose Secure so that all connections will be using HTTPS.

subsonic https

Your TLS certificate will be automatically installed.

Cheers!

I hope this tutorial helped you install Subsonic media server on Ubuntu 16.04. As always,

This site is using SEO Baclinks plugin created by InfoMotru.ro and Locco.Ro

LEAVE A REPLY

Please enter your comment!
Please enter your name here

1 × two =