493: Undecipherable

-Blog-

-Projects-

-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 mod_rewrite and mod_headers must be loaded.

Via VirtualHost:

1
2
3
4
5
6
7
8
9
10
11
12
13
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

<virtualhost 127.0.0.1:80>
  ProxyRequests Off
  ProxyPass / http://URL
  ProxyPassReverse / http://URL
  
  Header set Access-Control-Allow-Origin "*
  Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"

</virtualhost>

Via .htaccess:

1
2
3
4
5
6
RewriteEngine  on
RewriteBase /
RewriteRule  ^(.*)  http://URL  [P,L,QSA]

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

PS: Be aware of the security implications!