CORS (Access Control Allow Origin) on Apache Proxy issue
Asked Answered
F

2

6

I need to send a CORS header from my map server (QGIS mapserver) that use a fast cgi with Apache 2.4.* on the port 8080.

I configured the with a simple

<VirtualHost *:8080>
   [...]
   Header set Access-Control-Allow-Origin "*"
</VirtualHost>

and it works.

I want to set a proxy to avoid the specification of the port in the URL. I have configured another Virtualhost in the port 80:

<VirtualHost *:80>
    ProxyPass /cgi-bin/ http://localhost:8080/
    ProxyPassReverse /cgi-bin/ http://localhost:8080/

    # Is useful this?
    Header set Access-Control-Allow-Origin "*"
</VirtualHost>

but the header is not propagated. There is a solution?

Flux answered 15/7, 2016 at 15:42 Comment(0)
C
9

Add always

Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Max-Age "1000"
Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"

And, enable headers module

a2enmod headers
Capitalistic answered 22/5, 2017 at 14:34 Comment(1)
it is not obvious that a2enmod is installed on the server. better to refer to conf filesSacral
A
6

This worked for me - using LocationMatch with ProxyPass and Header set:

<VirtualHost *:80>

  <LocationMatch "/cgi-bin/">
    ProxyPass http://localhost:8080/
    ProxyPassReverse http://localhost:8080/

    Header add Access-Control-Allow-Origin "*"
  </LocationMatch>

</VirtualHost>
Annunciator answered 8/5, 2019 at 17:6 Comment(1)
I used <Location> instead of <LocationMatch> but it worked all the same!Unmanned

© 2022 - 2024 — McMap. All rights reserved.