Forum

Too many redirects in reversed proxy

Luis Mendes
4 February 2016, 18:32
Hi,

The incoming Hiawatha server has a reverse proxy configuration like:
VirtualHost {
Hostname = website2.eu, www.website2.eu
ReverseProxy .* http://192.168.0.6:80/
WebsiteRoot = /usr/local/www/dummy/index.html
}


The receiving Hiawatha server that should handle requests to website2.eu has the following configuration:
Binding {
Port = 80
Interface = 192.168.0.6
BindingId = wp
}

Binding {
Port = 443
Interface = 192.168.0.6
BindingId = wpssl
TLScertFile = /usr/local/etc/ssl/website2_wosign.pem
}

VirtualHost {
Hostname = www.website2.eu, website2.eu
EnforceFirstHostname = yes
RequiredBinding = wp
WebsiteRoot = /usr/local/www/wordpress
}

VirtualHost {
Hostname = www.website2.eu, website2.eu
EnforceFirstHostname = yes
RequiredBinding = wpssl
TLScertFile = /usr/local/etc/ssl/website2_wosign.pem
UseToolkit = denied
}


This site (wordpress) is using php-fpm, not shown.

The behavior I want is that when a user tries to access the site via
http://website2.eu
it should be redirected to its www. counterpart.
And when using https, the same thing, from
https://website2.eu
to
https://www.website2.eu
.

The present configuration causes a This webpage has a redirect loop or similar message both in Firefox and Chromium.
Note: in my last attempt, I changed a:
UrlToolkit {
ToolkitID = redirect
Match ^/(.*) Redirect http://www.website2.eu/$1
}

and, instead, placed the EnforceFirstHostname = yes to try to avoid those redirects, but to no success. Maybe this directive doesn't mean what I thing it does.

So, what is wrong with my config? In the firsts Hiawatha server configuration? in the receiving website2 configuration? How to do it?
Hugo Leisink
8 February 2016, 09:30
The redirect can be at many places. My advice is to place network sniffers before and after the proxy to look at both the HTTP request and response. This should give you a more detailed view of what's going on.
Luis Mendes
13 February 2016, 16:44
Hi Hugo,

What about proxying SSL accesses?
In my message, I tried to HTTP proxying with this:
VirtualHost {
Hostname = website2.eu, www.website2.eu
ReverseProxy .* http://192.168.0.6:80/
WebsiteRoot = /usr/local/www/dummy/index.html
}


But, how should I do it for port 443, when the first Hiawatha server is only serving 443 for local host with a different certificate?

And would you mind explaining if the EnvorceFirstHostname is meant (or not), for example, to have naked URLs being returned as www. domains?
Hugo Leisink
14 February 2016, 19:03
Use this:
ReverseProxy .* https://192.168.0.6/


EnforceFirstHostname redirects to the first hostname in the Hostname list when a different hostname is used in the URL bar. So, in you example above, Hiawatha will redirect to 'website2.eu' when someone used 'www.website2.eu'.
This topic has been closed.