493: Undecipherable

-Blog-

-Projects-

-Urlaub-

-About me-

-RSS-

Reverse proxy with CORS with Apache2

Dennis Guse

For the implementation of a Javascript-Client, I needed a CORS enabled reverse-proxy.

Uses apache2 and modrewrite and modheaders must be loaded.

Via VirtualHost:

 1 LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
 2 LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
 3 LoadModule 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:

1 RewriteEngine  on
2 RewriteBase /
3 RewriteRule  ^(.*)  http://URL  [P,L,QSA]
4 
5 Header set Access-Control-Allow-Origin "*"
6 Header set Access-Control-Allow-Headers "Origin, Content-Type, Accept"

PS: Be aware of the security implications!