2 methods to proxy your Shoutcast Stream for Free if you already have a Dedicated or VPS Server

2 methods to proxy your Shoutcast Stream for Free if you already have a Dedicated or VPS Server

Do to recent browser upgrades Google Chrome especially on how Mixed Content will be blocked.

Chrome and Safari block non SSL Shoutcast Streams from playing on websites that use the HTTPS SSL.

This is a quick work around method to make your streams work on a SSL website.

First Method PHP SSL PROXY

SHOUTcast doesn’t support SSL/HTTPs. The shoutcast service on port like 8000 is an unencrypted server for HTTP and ICY. So Shoutcast need proxy / restream HTTP stream to HTTPS.

You can use PHP or NodeJS or NGINX to restream Radio Streams. Re-Stream Radio Shoutcast / Icecast using Node JS

View image on Twitter
Re-Stream PHP Proxy file – stream/index.php
<?php 

/*

Icecast / Shoutcast MP3 Radio Stream 

Shoutcast V1 (http://shoutcast-server-ip:port/) 
Shoutcast V2 (http://shoutcast-server-ip:port/streamname) 
Icecast V2 (http://icecast-server-ip:port/streamname)

Type: Audio
Codec: MPEG Audio layer 1/2 (mpga)
Channels: Stereo
Sample rate: 44100 Hz
Bitrate: 128 kb/s

*/

header('Content-Type: audio/mpeg');

$server = "[Server-IP-Address]";
$port = "[Port]";
$mount = "[Mount-Point]";

// HTTP Radio Stream URL with Mount Point
$url = "http://".$server.":".$port."/".$mount;

// Open Radio Stream URL
// Make Sure Radio Stream [Port] must be open / allow in this script hosting server firewall 
$f=fopen($url,'r');

// Read chunks maximum number of bytes to read
if(!$f) exit;
while(!feof($f))
{
	echo fread($f,128);  
	flush();
}
fclose($f);

?>

.htaccess – stream/.htaccess

<FilesMatch "mp3$">
    SetHandler application/x-httpd-php5
</FilesMatch>

<IfModule mod_rewrite.c>

RewriteEngine On
#RewriteBase /

# Redirect MP3 to PHP
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*).mp3$ index.php [L]

</IfModule>

So if you host these files on HTTPS enabled server in folder “stream” …. Radio Stream Proxy URL will look like

https://www.domain.com/stream/audio.mp3

resourced from: https://www.svnlabs.com/blogs/radio-icecast-shoutcast-php-proxy-to-re-stream-radio-stream-on-https/

 

Method 2: Using Stunnel to add ssl to shoutcast (or any service that does not have ssl)

Stunnel is a proxy designed to add TLS encryption functionality to existing clients and servers without any changes in the programs’ code.

First stunnel must be installed. Many OS’s have stunnel preinstalled: so try running stunnel first. If not install with your OS’s package management tool such as

centos: yum install stunnel
ubuntu: apt-get install stunnel

Once stunnel is installed you can begin. First a config file is needed. In this example shoutcast is installed already and running on port 8000. It is listening on localhost only. Create the file

/etc/stunnel/stunnel.conf


client=no
[shoutcast]
accept=8002
connect=localhost:8000
cert = /etc/stunnel/stunnel.pem

Now create the PEM file /etc/stunnel/stunnel.pem

The format is

rsa key first
certificate second
cabundle/intermediate third

Set permissions to 600
chmod 600 /etc/stunnel/stunnel.pem

Now stunnel can be started with the command /usr/bin/stunnel and we can connect to port 8002 over ssl.

from source: https://www.interserver.net/tips/kb/using-stunnel-to-add-ssl-to-shoutcast-or-any-service-that-does-not-have-ssl/

Leave a Reply