Configure Madsonic Reverse Proxy nginx Linux

nginx-madsonic-reverse-proxyConfigure your Madsonic reverse proxy with nginx on Linux for convenient remote access. For ultimate convenience with your reverse proxy for people with dynamic IP addresses, use a free dynamic DNS service like AfraidDNS (guide for automating), DuckDNS or No-IP.

After completing this Madsonic reverse proxy tutorial you will be able to access Madsonic using your custom DNS address like instead of http://IP:4040. This Madsonic reverse proxy how-to was tested on Debian and Ubuntu but the nginx virtual host should work on any Linux system (CentOS, Red Hat, Fedora, Arch etc). I will assume you followed the install madsonic guide.

Configure Madsonic Reverse Proxy nginx Linux

This Madsonic reverse proxy tutorials involves two steps, enabling Madsonic's custom web root and adding the custom location into your nginx reverse proxy virtual host.

Enable Madsonic Reverse Proxy

First we need to enable the custom web root for Madsonic by editing its parameters configuration file

sudo nano /etc/default/madsonic

Add --context-path thanks to this post and choose your location (here /madsonic) that you want to use for the reverse proxy

MADSONIC_ARGS="--context-path=/madsonic --init-memory=256 --max-memory=512"

Ctrl+X, Y and Enter to save

Restart the Madsonic service now

sudo service madsonic restart

Now you can test the new location with http://ip.address:4040/madsonic

Install nginx

sudo apt-get update
sudo apt-get install nginx -y

Create the reverse proxy nginx vhost if you don't have one already

sudo nano /etc/nginx/sites-available/reverse

Add this whole block if the vhost didn't exist, is a sample free dynamic DNS address from Afraid (guide)

If you already have a reverse proxy then just add the location block

server {
listen 80;

location /madsonic {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Enable the nginx reverse proxy vhost if you haven't already

sudo ln -s /etc/nginx/sites-available/reverse /etc/nginx/sites-enabled/reverse

Disable default site

sudo unlink /etc/nginx/sites-enabled/default

Test the nginx configuration

sudo nginx -t

If all was successful then reload nginx

sudo service nginx reload

Now you can go to the local IP address http://ip.address/madsonic

If you want to enable https nginx reverse proxy see this guide and authentication with brute force protection with this guide.