mod_rewrite proxy targets must be allowed first

I was trying to install a proxy redirect on my server in order to bypass the same origin policy for GWT Ajax requests. We are not using the default java servlets but a perl backend.

Therefore I wanted to rewrite a path „http://myhost/mk/*“ to the host where the actual request endpoint was „http://targethost/$1“.

The Idea was to use mod_rewrite and first of all it had to be enabled. Additionally mod_proxy is used if proxy rewrites are involved. On debian this works using:

$ a2enmod rewrite; a2enmod proxy_http

The vhost config looks like this:

<VirtualHost myhost:80>
ServerName gt.myhost

RewriteEngine On
RewriteLogLevel 3
RewriteLog "/var/log/apache2/rewrite.log"
RewriteRule ^/mk/(.*) http://targethost/$1 [P]

# Allow the proxy to targethost ...
<Proxy http://targethost/*&gt;
Order deny,allow
Allow from all
</Proxy>

DocumentRoot /var/www/gt
</VirtualHost>

Important is the Proxy element here, which was not obvious to me from the start. I missed it and just got the following output in rewrite.log and error.log when trying to call http://gt.myhost/mk/login.

(2) rewrite '/mk/login' -> 'http://targethost/login'
(2) forcing proxy-throughput with http://targethost/login
(1) go-ahead with proxy request proxy:http://targethost/login [OK]

[error] client denied by server configuration: proxy:http://targethost/login

So, make sure you got the Proxy Element right, too, when using mod_rewrite and [P].

References:

mod_rewrite manual
apache rewrite guide
Ubuntu mod_rewrite Problem

Schreibe einen Kommentar

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s

%d Bloggern gefällt das: