Mobile app version of vmapp.org
Login or Join
Annie201

: Access resources of secondary server running different port apache2 I'm currently running a main server from a raspberry pi (32 GB) and a secondary server (4 TB) running as the file storage

@Annie201

Posted in: #Apache2 #Configuration #HttpHeaders

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: 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 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?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Annie201

1 Comments

Sorted by latest first Latest Oldest Best

 

@Bryan171

this is how to fix this:


sudo nano /etc/apache2/apache2.conf
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>



Enable headers in config file: sudo a2enmod headers
Check for errors do: sudo apachectl -k graceful
sudo service apache2 reload
sudo service apache2 restart


Done

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme