Reverse proxy with CORS with Apache2
Dennis GuseFor the implementation of a Javascript-Client, I needed a CORS enabled reverse-proxy.
Uses apache2 and modrewrite and modheaders must be loaded.
Via VirtualHost:
1LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
2LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
3LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so
4
5<virtualhost 127.0.0.1:80>
6 ProxyRequests Off
7 ProxyPass / http://URL
8 ProxyPassReverse / http://URL
9
10 Header set Access-Control-Allow-Origin "*
11 Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"
12
13</virtualhost>
Via .htaccess:
1RewriteEngine on
2RewriteBase /
3RewriteRule ^(.*) http://URL [P,L,QSA]
4
5Header set Access-Control-Allow-Origin "*"
6Header set Access-Control-Allow-Headers "Origin, Content-Type, Accept"
PS: Be aware of the security implications!