Shoutcast doesn’t support SSL natively and is built to run over plain HTTP. To serve Shoutcast streams securely via HTTPS, you need a workaround since direct SSL on Shoutcast isn’t possible.
Option 1: Use a Reverse Proxy
One common solution is to place a reverse proxy like Nginx or Varnish in front of your Shoutcast server. The proxy handles the SSL termination — meaning it manages the HTTPS connection — then forwards the request to Shoutcast over HTTP. This setup allows you to serve your stream securely without modifying Shoutcast itself.
Here is a guide from Vultr on Setting up Shoutcast Server and Nginx Proxy on Ubuntu.
Option 2: Use a PHP Proxy Script
A simpler and more affordable approach is to create a small PHP script on your web server. This script connects to the Shoutcast stream over HTTP, then serves the audio through your HTTPS website. This method also prevents CORS (Cross-Origin Resource Sharing) errors when embedding the stream on your pages.
Here’s an example PHP proxy script you can use:
<?php
$streamUrl = 'http://IP_ADDRESS_HERE:STREAM_PORT/sid=1';
header('Content-Type: audio/mpeg');
header('Cache-Control: no-cache');
header('Pragma: no-cache');
header('Connection: close');
$stream = fopen($streamUrl, 'rb');
if (!$stream) {
http_response_code(500);
echo "Failed to connect to the stream.";
exit;
}
while (!feof($stream)) {
$buffer = fread($stream, 8192); // Read 8KB chunks
if ($buffer === false) break;
echo $buffer;
flush();
}
fclose($stream);
?>
Save this as stream.php
on your website. Then, if your website domain is example.com
, you can access your Shoutcast stream securely via:
https://example.com/stream.php
By using a reverse proxy or a simple PHP proxy script, you can easily serve your Shoutcast stream over HTTPS without complicated SSL configurations on the Shoutcast server itself. This method is both practical and cost-effective, helping you maintain a secure and smooth streaming experience.