Showing posts with label Reverse Proxy. Show all posts
Showing posts with label Reverse Proxy. Show all posts

Friday, July 26, 2013

Reverse proxy with CORS usin Apache2

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

Here is one using apache2 (Virtual Host):
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so 
LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so


 ProxyRequests Off

 ProxyPass / http://SERVER
 ProxyPassReverse / http://SERVER

 Header set Access-Control-Allow-Origin "*"
 Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"

Here is one using apache2 (.htaccess): mod_rewrite and mod_headers must be loaded.
RewriteEngine  On
RewriteBase /
RewriteRule  (.*)  http://SERVER/$1  [P,L]

 Header set Access-Control-Allow-Origin "*"
 Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"
PS: Be aware of the security implications!