In this tutorial I will explain how to use Sonerezh and Nginx to listen to your music any where you are on most devices.
Why would you want to do this when you can use the Kodi web server with Chorus2?
It’s a difficult task to get SSL security working on Kodi’s web server. If you can get it to work with the Chorus2 web gui, then by all means tell me how you did it here. But until there’s a proper and easy way to do that, an alternative is the best way to go.
In a shorter answer: It’s easier to setup and more secure. If you run this outside of your local network you should do this rather than reverse proxying the Kodi webserver.
Don’t run the Kodi web server outside your local network without SSL. They can do malicious things to Kodi and potentially damage it, making you have to reinstall it and maybe even lose data.
I have installed this on my Raspberry Pi 3, but should work on most Linux systems in general.
What you will need:
Some apt packages: nginx, php5-fpm php5-gd, php5-mysql, git, mariadb-server
Sonerezh
An SSH connection to your device.
Linux command line knowledge (I will be as thorough as I can)
This should work on any version of OSMC.
Use the following command to install the apt packages:
sudo apt install nginx php5-fpm php5-gd php5-mysql mariadb-server git
I will mainly be following the documentation of Sonerezh.
MariaDB Setup
You will be prompted to enter a root password for MariaDB when doing the command above, enter a secure password that you can remember or a randomly generated password that you can store in a password manager.
After this you will need to enter the database command line, you can do so by entering this command:
mysql -u root -p
This will prompt you to enter the password for the user root which you entered during the setup.
After this you will be in the MariaDB command line. Please enter the following commands:
CREATE DATABASE sonerezh;
This will create a database called sonerezh I advice to keep the name the same to make the guide more simpler.
Before pressing enter after the following command make sure to edit the password
GRANT ALL PRIVILEGES ON sonerezh.* TO 'sonerezh'@'localhost' IDENTIFIED BY 'edit-this';
Just press the left arrow key and edit the password.
Now enter the following command:
FLUSH PRIVILEGES;
And now you can exit MariaDB with this command:
exit;
And we’re now done with MariaDB!
Now to download Sonerezh!
We will be downloading Sonerezh to the folder /var/www/
.
cd /var/www
Now to clone the master branch from git to a folder called sonerezh
sudo git clone --branch master https://github.com/Sonerezh/sonerezh.git
This command might take some time depending on hardware and internet speed.
After it finishes make the user www-data
the owner of the folder.
sudo chown -R www-data: sonerezh/
Now you’re almost done.
NGINX Setup
You need to edit the file /etc/nginx/sites-available/default
you can do this by using nano (Which is the best command line editor )
sudo nano /etc/nginx/sites-available/default
Now delete everything, you can either do this by going to the bottom and removing everything character by character or go to the top and hold ctrl + k.
After that you can paste in the following config which is my personal config that works well.
# Redirect http -> https
server {
listen 80;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
root /var/www/sonerezh/app/webroot;
index index.php;
# Do SSL stuff...
ssl_certificate /etc/nginx/certs/cert.crt;
ssl_certificate_key /etc/nginx/certs/priv.key;
ssl_session_timeout 5m;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_protocols TLSv1.2;
# Optionally add basic auth
location / {
try_files $uri $uri/ /index.php?$args;
expires 14d;
add_header Cache-Control 'public';
}
# The section below handle the thumbnails cache, on the client (browser)
# side (optional but recommended)
location ~* /([^/]+_[0-9]+x[0-9]+(@[0-9]+x)?\.[a-z]+)$ {
try_files /img/resized/$1 /index.php?$args;
add_header Cache-Control 'public';
expires 14d;
access_log off;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi.conf;
# If fastcgi.conf is not available on your platform you may want to
# uncomment the following line
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
This config uses SSL encryption I strongly recommend you use SSL encryption for this setup, if you don’t want to use SSL with Sonerezh you can use the config below.
server {
listen 80;
server_name demo.sonerezh.bzh;
root /var/www/sonerezh/app/webroot;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
expires 14d;
add_header Cache-Control 'public';
}
# The section below handle the thumbnails cache, on the client (browser)
# side (optional but recommended)
location ~* /([^/]+_[0-9]+x[0-9]+(@[0-9]+x)?\.[a-z]+)$ {
try_files /img/resized/$1 /index.php?$args;
add_header Cache-Control 'public';
expires 14d;
access_log off;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi.conf;
# If fastcgi.conf is not available on your platform you may want to
# uncomment the following line
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
This config doesn’t use SSL and might not be the best choice if you want to use Sonerezh outside your local network. Please only use this if you know what you are doing.
Rember, you need to supply a certificate for SSL, you can get this from sites like Cloudflare or you can use Let’s Encrypt.
When you are done with the config you can exit Nano by doing the following:
Press ctrl + x It will prompt you to save, on your keyboard click: y
Then press enter.
Nano should have stopped and the file saved now enter the following command to restart nginx:
sudo nginx -s reload
If you run in to errors with Nginx please post them bellow and I’ll see what I can do.
If you want to change the port from 443 or 80 you can do so by changing the numbers on the listen
directive in the config file. Example: listen 1337 ssl;
without ssl: listen 1337;
Done!
Now go to the local IP of the device and follow the setup there.
If you want to “share” the music library from Kodi to Sonerezh you can choose the same Music directory where you keep your music for Kodi. (This is probably in the Music folder, /home/osmc/Home
for OSMC devices depends on your setup.)
General stuff
If you encounter any errors please post them and I’ll see if I can help you. Remember to Google your problems first, there might be an easy fix available, don’t be afraid to experiment!
If you find any tpos in this config please enlighten me about them, if you have any improvements please post that to.
Thanks for reading and hope all goes well.