1

I'm currently running a main server from a raspberry pi (32 GB) and a secondary server (4 TB) running as the file storage server. Both servers are running Debian Linux with Apache2 installed. I've been successful to bring PHP output from secondary server to main server with this code:

Main server:

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

Secondary Server

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

    //Rest of code
?>

So I came to the problem where the main server would be able to show pictures and play mp3/wav from the secondary server, but in my case, it wouldn't work with FLAC (with a bit of javascript code). Here is some useful info from apache2.conf:

<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: "Content-Length"
</IfModule>

Right now I get this error from google chrome:

XMLHttpRequest cannot load http://example.org:700/song.flac. Request header field Range is not allowed by Access-Control-Allow-Headers in preflight response.

I simply want to allow all traffic between the two servers to be secure and with no XMLHttpRequest errors. Is there something I can change in the config file to make this work?

  • Advanced server configuration is really best asked on Server Fault. Try adding: Header set Access-Control-Allow-Headers "Range" and then restart your server. If that doesn't work, then flag this to request migration. – dan Jan 21 '17 at 6:08
  • 1
    @dan Ok, I'll look in to what topics these forums take next time. But thanks, it worked! – Typewar Jan 21 '17 at 13:54
  • No problem. Can you add that as an answer and accept it when you can, so the question can be considered closed? Thanks. – dan Jan 22 '17 at 2:12
  • @dan Alright. I'll add the answer myself. – Typewar Jan 22 '17 at 2:25
1

this is how to fix this:

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

  2. Put in this code at the bottom:

.

<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. Enable headers in config file: sudo a2enmod headers

  2. Check for errors do: sudo apachectl -k graceful

  3. sudo service apache2 reload

  4. sudo service apache2 restart

Done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.