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 features
Note that Subsonic is closed-source since version 6.0.
Subsonic media server is written in Java, so you need to install Java runtime environment to run it. You can install openjdk 8 with the following command.
sudo apt install openjdk-8-jre
If you have previously installed Oracle Java 8, then there’s no need to install OpenJDK. Next, download Subsonic deb package with the following command, which downloads version 6.1.5. You can check out the latest version on Subsonic download page. If a new version is available, simply replace 6.1.5 with the new version number.
wget https://s3-eu-west-1.amazonaws.com/subsonic-public/download/subsonic-6.1.5.deb
Install it with dpkg
.
sudo dpkg -i subsonic-6.1.5.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
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 and click the Save button. Note that the folder must be accessible to the user Subsonic is running as. After folder is added, click “Scan media folder now” button and you will be able to listen to music in the Index page.
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
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 (subsonic.your-domain.com
)
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-get install software-properties-common sudo add-apt-repository ppa:certbot/certbot sudo apt-get update sudo apt-get install certbot python3-certbot-nginx
Then issue the following command, which uses Certbot Nginx plugin to automatically obtain and install TLS certificate. Replace red text with your actual data.
sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email your-email-address --domain subsonic.your-domain.com
Within a few seconds, you should see a congrats message like below which
means the certificate is successfully obtained.
Go to your Subsonic media server Web interface again, you will find HTTP
connection is automatically redirected to HTTPS secure connection. Next, we
need to modify the Nginx configuration file.
sudo nano /etc/nginx/conf.d/subsonic-proxy.conf
There’s now two server {…} blocks, becaus Certbot automatically configured the SSL server block (listen 443 ssl). In the SSL server block, add the following line in the location / {…} block.
proxy_redirect http:// https://;
This line will redirect any http server response to https server response, which is needed to properly display Subsonic settings page. Save and close the file. Test Nginx configuration and reload.
sudo nginx -t sudo systemctl reload nginx
If you prefer Apache to Nginx, then install it with:
sudo apt install apache2
To use Apache as a reverse proxy, we need to enable the proxy
modules
and the header module.
sudo a2enmod proxy proxy_http headers
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. Don’t forget to create DNS A record for this
sub-domain.
<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.
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-get install software-properties-common sudo add-apt-repository ppa:certbot/certbot sudo apt-get update sudo apt install certbot python3-certbot-apache
Then obtain and install a certificate using the apache plugin.
sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp --must-staple --email your-email-address -d subsonic.your-domain.com
Within a few seconds, you should see a congrats message like below which
means the certificate is successfully obtained.
Your TLS certificate will be automatically installed. Go to your Subsonic media server Web interface again, you will find HTTP connection is automatically redirected to HTTPS secure connection.
It is very easy to upgrade existing Subsonic server to the latest version. First go to Subsonic download page and download the latest Debian/Ubuntu package (6.1.2 in this example). You can get the download link in Firefox download manager as shown in the screenshot below.
Then in the terminal you can paste the download link after wget to download Subsonic from the command line.
wget https://s3-eu-west-1.amazonaws.com/subsonic-public/download/subsonic-6.1.2.deb
Next, use dpkg to install the deb package.
sudo dpkg -i subsonic-6.1.2.deb
Restart Subsonic Systemd service and you are done.
sudo systemctl restart subsonic