访问副服务器资源运行不同端口apache2

Access resources of secondary server running different port apache2

我目前 运行 来自 raspberry pi (32 GB) 的主服务器和辅助服务器 (4 TB) 运行 作为文件存储服务器。两台服务器都是安装了 Apache2 的 运行 Debian Linux。我已经成功地将 PHP 输出从辅助服务器带到主服务器,代码如下:

主服务器:

<?php
    $results = file_get_contents('http://example.org:700/handle.php');
    echo $results;
?>

辅助服务器

<?php
    header('Access-Control-Allow-Origin: http://example.org');

    //Rest of code
?>

所以我遇到了主服务器能够显示图片并从辅助服务器播放 mp3/wav 的问题,但在我的情况下,它不适用于 FLAC(有一点javascript 代码),它只是向我展示了这个错误:

XMLHttpRequest cannot load http://example.org:700/music/soundfile.flac. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.org' is therefore not allowed access.

我知道 javascript 编码没有任何问题,因为它会像这个例子一样播放来自其他网站的音乐:Debussy_-_Pour_les_accords.flac 并且之前工作得很好。

我只是想让两台服务器之间的所有流量都安全并且没有 Access-Allow-Origin 错误。 apache2.conf 或其他配置文件中是否有可以帮助我解决此问题的内容?

https://whosebug.com/a/35707821/6802309

看起来很简单。 这是解决此问题的方法:

  1. sudo nano /etc/apache2/apache2.conf

  2. 在底部输入这段代码:

.

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin: "http://example.org"
    Header set Access-Control-Allow-Credentials: true
    Header set Access-Control-Expose-Headers: "Content-Length"
    Header set Access-Control-Allow-Methods: "POST, GET, PUT, OPTIONS, DELETE, HEAD"
    Header set Access-Control-Allow-Headers: "Range"
</IfModule>
  1. 在配置文件中启用headers:sudo a2enmod headers

  2. 检查错误:sudo apachectl -k graceful

  3. sudo service apache2 reload

  4. sudo service apache2 restart

完成