icecast和Apache在同一个端口(mod_proxy,mod_rewrite)

我有一个在端口8000上运行的icecast服务器。我可以从互联网上以LINK1(见下文)的forms访问服务器。 另外,我创build了一个HTML页面,其中包含一些embedded了HTML5audio播放器的信息。 如果作为http主机域名点com访问工作正常。

<html> <head> <title>Radio</title> </head> <body> <p>Some text</p> <audio controls> <source src="LINK1" type="audio/ogg"> </audio> </body> </html> 

问题是,如果端口8000在侦听器计算机上被阻止,他们听不到stream。 所以,我试图使用mod_proxy和mod_rewrite但无济于事。 如果我使用下面的configuration,我可以绕过端口8000,并且在端口80上stream式传输,但是http host dot dot com只显示​​audio播放器,而不是整个HTML页面。 我尝试了不同的组合和谷歌search,我只是无法弄清楚。

我的问题是如果这是一个可行的解决scheme。 在Apache 80和icecast 8000代理通过相同的端口? 我需要两个IP吗? 那么如果我使用两个IP,什么是正确的configuration。 这是我的Apache虚拟主机configuration。

 ProxyRequests Off ProxyPass / LINK1 ProxyPassReverse / LINK1 #RewriteEngine On #RewriteRule ^/mount\.ogg$ LINK2 [P] 

请注意,mount.ogg是一个不存在的文件。 这只是icecast的一个挂载点。

==>在这里发布链接(至less需要10个声望)LINK1: http ://host.domain.com:8000/mount.ogg LINK2: http ://host.domain.com/mount.ogg

谢谢

我不想在我的唯一外部IP地址上select运行在端口80上的Icecast和运行在端口80上的所有我的Apache虚拟主机。

我不希望在防火墙上打开8000端口,因为我希望所有的用户都能够访问Icecast,甚至是企业防火墙后的用户。

所以我设法运行Apache 2.2侦听端口80,Icecast 2.4.1侦听同一主机上的8000端口。

我添加了一个新的虚拟主机radio.domain.com(侦听80端口),将Icecaststream量路由到本地Icecast服务器(监听端口8000):

 <VirtualHost *:80> ServerName radio.domain.com ServerAdmin [email protected] ProxyPreserveHost On ProxyPass / http://localhost:8000/ ProxyPassReverse / http://localhost:8000/ </VirtualHost> 

然后,我可以使用像http://radio.domain.com/my_stream这样的地址将VLC / Winamp等audio客户端连接到Icecast挂载点。

但是,当连接到Icecast虚拟主机http://radio.domain.com/网页时,m3u和xspf文件仍然暴露URL http://radio.domain.com:8000/my_stream与那个恼人的端口8000.然后下载这些文件的人不能连接到Icecast服务器,因为他们试图连接到错误的端口。 dir.xiph.org上的YP更新也是如此。

然后我下载了Icecast 2.4.1的源代码,并修改它添加一个新的选项:

 <exposed-port>80</exposed-port> 

您可以在https://damiengarrido.wordpress.com/2015/03/22/icecast-reachable-behind-reverse-proxy/上find该补&#x4E01;

如果需要,我可以在这里粘贴补丁。

首选的方法是让Icecast直接监听端口80,毕竟它是一个HTTP服务器。

反向代理它不被推荐的原因很多。

  • 许多长期居住的连接,如果没有正确configuration将使Apache下来
  • 一些传统的function(源,统计信息)不可访问,只能通过简单的HTTP在2.4.1和未来版本的Icecast
  • YP公共目录报告代码不能被反向代理识别,这会破坏列表
  • 网页界面和生成的播放列表,至less不容易得到正确的

总而言之,如果您正在从事生产设置工作,并且是一名专业人士,他们确切地知道自己在做什么,这是可能的,但并不容易。 如果你只是随便的想着“哦,嘿,让我们把这个像其他所有东西一样反向代理”,那么你就有些痛苦了。

获得一个额外的IP,使Icecast听到端口80,简单。

我能够find一个解决scheme(部分)使用两个虚拟主机。 对于可以访问端口8000的监听程序,configuration保持与上述相同,即减去代理指令。 但是在第一个虚拟主机的HTML页面中,我添加了一个链接来打开一个指向我使用ProxyReverse的第二个虚拟主机的新窗口。 所以,第一个虚拟主机的HTML文件是

 <audio controls> <source src="LINK1" type="audio/ogg"> </audio> <a href="/" onclick="window.open('LINK3', 'newwindow','width=300, height=100'); return false;"> No audio?</a> 

LINK3链接到第二个虚拟主机,例如host2 dot domain dot com正斜杠

然后,第二个虚拟主机的configuration实际上是代理反向的。

 ProxyRequests Off ProxyPass / LINK1 ProxyPassReverse / LINK1 

也许我可以使用一个1像素的框架,并指向那里的链接,但我也很好这个解决scheme。

谢谢

我遇到了同样的问题,我在Ubuntu 16.04的apache2上运行在端口443上的我自制的index.php页面。 我想使用我自己的网页,并通过音乐stream(非ssl)的“脚本”和当前正在播放(也是非ssl)。 发生了什么事情,一切都可以通过端口80工作,但是当我切换到端口443,浏览器(特别是铬)将阻止我的“不安全的脚本”,并没有发生声音。

所以,经过互联网searchfind这个,但没有怎么做,我终于明白了!

这是我为有兴趣的人设立的:

  1. 运行在端口8080上的Windows上的Icecast 2.4.3
  2. 运行Oracle VirtualBox的Ubuntu 16.04 LTS包含近20个网站
  3. 我使用MediaMonkey 4.1.16和一个名为“edcast”的插件来连接到Icecast

Apache2的conf文件:

 <IfModule mod_ssl.c> <VirtualHost *:443> ServerName radio.domain.com DocumentRoot /var/www/radio.domain.com <Directory /var/www/radio.domain.com> Options Indexes FollowSymLinks MultiViews Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined SSLCertificateFile /etc/letsencrypt/live/radio.domain.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/radio.domain.com/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf Options -Includes -ExecCGI RewriteEngine On RewriteCond %{THE_REQUEST} !HTTP/1.1$ RewriteRule .* - [F] LimitRequestBody 512000 Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload" Header always set X-Frame-Options DENY FileETag None TraceEnable off Header set X-XSS-Protection "1; mode=block" Timeout 60 <Proxy *> Order deny,allow Allow from all </Proxy> ProxyRequests Off ProxyPreserveHost On SSLProxyEngine On RequestHeader set Front-End-Https "On" ProxyPass /stream http://192.168.1.2:8080/stream #IP and port of local computer on same network ProxyPassReverse /stream http://192.168.1.2:8080/stream #IP and port of local computer on same network ProxyPass /np.xsl http://192.168.1.2:8080/np.xsl #np.xsl is a file that I call using ajax from my index.php page to get the track currently playing ProxyPassReverse /np.xsl http://192.168.1.2:8080/np.xsl #np.xsl is a file that I call using ajax from my index.php page to get the track currently playing </VirtualHost> </IfModule> 

我的np.xsl文件(在Icecast“web”目录中):

 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output omit-xml-declaration="yes" method="text" indent="no" media-type="text/javascript" encoding="UTF-8"/> <xsl:strip-space elements="*"/> <xsl:template match="/icestats"> parseMusic({ <xsl:for-each select="source">"<xsl:value-of select="@mount"/>":{ "server_name":"<xsl:value-of select="server_name"/>", "title":"<xsl:if test="artist"><xsl:value-of select="artist" /> - </xsl:if><xsl:value-of select="title" />", "bitrate":"<xsl:value-of select="bitrate" />"} <xsl:if test="position() != last()"><xsl:text>,</xsl:text> </xsl:if> </xsl:for-each>}); </xsl:template> </xsl:stylesheet> 

我的index.php页面:

 <!DOCTYPE html> <html> <head> <link rel="icon" href="favicon.ico" type="image/x-icon"> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"> <title id="track-title"></title> <style> html{width:100%;} body{background-color:#bfbfbf; text-align:center; font-family:Helvetica;} #wrapper{position:absolute; max-width:550px; left:50%; transform:translate(-50%,0); -ms-transform:translate(-50%,0); -webkit-transform:translate(-50%,0); margin-right:-50%; text-align:center; box-shadow:1px 1px 20px 5px #4d4d4d;} </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <script> function updateTitle() { $.ajax({ type: 'GET', url: 'https://radio.domain.com/np.xsl', jsonpCallback: 'parseMusic', dataType: 'jsonp' }).then(function (data) { var $track = $('#track-title').text(data['/stream'].title); var text = $track.text(); $track.text(text.replace(" - MediaMonkey","")); }).fail(function (e) { console.log(e); }).always(function () { setTimeout(updateTitle, 5000); }); } $(updateTitle); function updateTitle2() { $.ajax({ type: 'GET', url: 'https://radio.domain.com/np.xsl', jsonpCallback: 'parseMusic', dataType: 'jsonp' }).then(function (data) { var $track = $('#track-title2').text(data['/stream'].title); var text = $track.text(); $track.text(text.replace(" - MediaMonkey","")); }).fail(function (e) { console.log(e); }).always(function () { setTimeout(updateTitle2, 5000); }); } $(updateTitle2); </script> </head> <body> <div id="wrapper"> <h2>Live Radio</h2></br> <h4><span id="track-title2"></span></h4></br></br> <audio controls src="https://radio.domain.com/stream" type="audio/mp3"></audio><br></br> </div> </body> </html> 

最后我的icecast.xml代码:

 <icecast> <location>Minneapolips, MN</location> <admin>[email protected]</admin> <hostname>radio.domain.com</hostname> <limits> <clients>50</clients> <sources>1</sources> <queue-size>524288</queue-size> <client-timeout>30</client-timeout> <header-timeout>15</header-timeout> <source-timeout>10</source-timeout> <burst-on-connect>1</burst-on-connect> <burst-size>65535</burst-size> </limits> <authentication> <source-password>hackme</source-password> <relay-password>hackme</relay-password> <admin-user>admin</admin-user> <admin-password>hackmemore</admin-password> </authentication> <listen-socket> <port>8080</port> <shoutcast-mount>/stream</shoutcast-mount> </listen-socket> <http-headers> <header name="Access-Control-Allow-Origin" value="*" /> </http-headers> <fileserve>1</fileserve> <paths> <logdir>./log</logdir> <webroot>./web</webroot> <adminroot>./admin</adminroot> <alias source="/" destination="/status.xsl"/> </paths> <logging> <accesslog>access.log</accesslog> <errorlog>error.log</errorlog> <loglevel>4</loglevel> <!-- 4 Debug, 3 Info, 2 Warn, 1 Error --> <logsize>10000</logsize> <!-- Max size of a logfile --> </logging> </icecast> 

它看起来像: 收音机