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

DocumentRoot /var/www/gt

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].


mod_rewrite manual
apache rewrite guide
Ubuntu mod_rewrite Problem

Kommentar verfassen

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

Du kommentierst mit Deinem Abmelden /  Ändern )

Google Foto

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


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


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

Verbinde mit %s

%d Bloggern gefällt das: