Skip to content

Spotisub with reverse proxy

Fabio Valentino edited this page Oct 28, 2024 · 4 revisions

NGINX

This is a sample nginx configuration to use Spotisub with an nginx reverse proxy

user nginx nginx;

error_log /var/log/nginx/error_log info;

events {
	worker_connections 1024;
	use epoll;
}

http {
	include /etc/nginx/mime.types;

	# Unknown stuff is considered to be binaries
	default_type application/octet-stream;

	# Set a reasonably informing log format
	log_format main
		'$remote_addr - $remote_user [$time_local] '
		'"$request" $status $bytes_sent '
		'"$http_referer" "$http_user_agent" '
		'"$gzip_ratio"';

	# Improve file sending to client by avoiding userspace copying
	tcp_nopush on;
	sendfile on;

	# Indexes are html by default
	index index.html;

	# General catch-all for HTTPS redirection, we don't like serving plain HTTP
	server {
		listen 80 default_server;
		return 301 https://$host$request_uri;
	}

	# main server on HTTPS only
	server {
		server_name xxx.mydomain.com
		listen 443 ssl;
		http2 on;

 		access_log /var/log/nginx/xxx.mydomain.com_access_log main;
		error_log /var/log/nginx/xxx.mydomain.com_error_log notice; #info;

		# For your nice webpage
		location / {
			root /var/www/html
		}

		# redirect /spotisub to /spotisub/
		location = /spotisub {
			return 301 https://$host/spotisub/;
		}
		
		location /spotisub/ {
				rewrite ^/spotisub/(.*) /$1 break;
				proxy_redirect  http://127.0.0.1:5183 /spotisub;
				proxy_pass http://127.0.0.1:5183/;
				proxy_http_version 1.1;
				gzip off;
				gunzip on;
				proxy_set_header Accept-Encoding "";
				proxy_set_header Connection $http_connection;
				proxy_set_header Upgrade $http_upgrade;
				sub_filter "src=\"/" "src=\"/spotisub/";
				sub_filter "href=\"/" "href=\"/spotisub/";
				sub_filter_once off;
				sub_filter_types text/xml text/css text/javascript application/javascript;
		}


                #socket.io will clash with anything else using that path on your reverse proxy, this will be fixed in the future
		location /socket.io/ {
				proxy_pass http://127.0.0.1:5183/;
				proxy_http_version 1.1;
				proxy_set_header Connection $http_connection;
				proxy_set_header Upgrade $http_upgrade;
		}

		# Use Let's Encrypt Certbot to manage SSL stuff!
		ssl_certificate /etc/letsencrypt/live/xxx.mydomain.com/fullchain.pem; # managed by Certbot
		ssl_certificate_key /etc/letsencrypt/live/xxx.mydomain.com/privkey.pem; # managed by Certbot
		include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
		ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
	}
}