Forum

ReverseProxy

Gary
7 June 2012, 05:55
Hiawatha version: 8.2
Operating System: FreeBSD 9.0-RELEASEp2

I am planning to switch from Pound/Apache to Nginx/Hiawatha, but since Hiawatha now has reverse proxy functionality I can eliminate Nginx. However, I am unsure of what I would need in hiawatha.conf.

This is part of the nginx.conf to handle reverse proxying now:
        server {
listen 192.168.1.104:80;
server_name mydomain.com www.mydomain.com;
access_log /var/log/nginx/mydomain.com.access.log ;
error_log /var/log/nginx/mydomain.com.error.log ;

location / {
proxy_pass http://192.168.1.101:8080/ ;
include /usr/local/etc/nginx/proxy.conf;
}
}


And in my current hiawatha.conf for the relevant sections
Binding {
Port = 80
Interface = 192.168.1.26
}

Binding {
BindingID = BIND1
Interface = 192.168.1.101
Port = 8080
}

VirtualHost {
Hostname = www.mydomain.com
WebsiteRoot = /var/www/domains/www.mydomain.com/htdocs
RequiredBinding = BIND1
StartFile = index.html
AccessLogfile = /var/www/domains/www.mydomain.com/logs/access.log
ErrorLogfile = /var/www/domains/www.mydomain.com/logs/error.log
}


So I have nginx listening on 1.104 and hiawatha listening on 1.26 and when a request for www.mydomain.com comes in on 1.104 on nginx, it is redirected to hiawatha which serves the VirtualHost mydomain.com on 1.101:8080.

How would I be able to do that with Hiawatha using ReverseProxy and Hiawatha also serving the Virutal Hosts?
Hugo Leisink
7 June 2012, 09:43
If you replace nginx with Hiawatha, use the following reverse proxy configuration to redirect requests to the other Hiawatha webserver:
VirtualHost {
Hostname = www.mydomain.com
....
ReverseProxy .* http://192.168.1.101:8080/
}

This is for the 1.104 server.
Gary
7 June 2012, 13:28
So for a Hiawatha reverse proxy to replace the nginx reverse proxy, I could use a config like this for the 4 domains I have (ficticious domains used as examples)?
Binding {
Port = 80
Interface = 192.168.1.104
}

VirtualHost {
Hostname = www.mydomain.com
ReverseProxy .* http://192.168.1.201:8080/
}

VirtualHost {
Hostname = www.otherdomain.com
ReverseProxy .* http://192.168.1.202:8080/
}

VirtualHost {
Hostname = www.itsmydomain.com
ReverseProxy .* http://192.168.1.203:8080/}
}

VirtualHost {
Hostname = www.anotherdomain.com
ReverseProxy .* http://192.168.1.204:8080/
}


And for the other web server that serves content I could keep my original hiawatha.conf?
Binding {
Port = 80
Interface = 192.168.1.26
}

Binding {
BindingID = BIND1
Interface = 192.168.1.201
Port = 8080
}

Binding {
BindingID = BIND2
Interface = 192.168.1.202
Port = 8080
}

Binding {
BindingID = BIND3
Interface = 192.168.1.203
Port = 8080
}

Binding {
BindingID = BIND4
Interface = 192.168.1.204
Port = 8080
}

VirtualHost {
Hostname = www.mydomain.com
WebsiteRoot = /var/www/domains/www.mydomain.com/htdocs
RequiredBinding = BIND1
StartFile = index.html
AccessLogfile = /var/www/domains/www.mydomain.com/logs/access.log
ErrorLogfile = /var/www/domains/www.mydomain.com/logs/error.log
}

VirtualHost {
Hostname = www.otherdomain.com
WebsiteRoot = /var/www/domains/www.otherdomain.com/htdocs
RequiredBinding = BIND2
StartFile = index.html
AccessLogfile = /var/www/domains/www.otherdomain.com/logs/access.log
ErrorLogfile = /var/www/domains/www.otherdomain.com/logs/error.log
}

VirtualHost {
Hostname = www.itsmydomain.com
WebsiteRoot = /var/www/domains/www.itsmydomain.com/htdocs
RequiredBinding = BIND3
StartFile = index.html
AccessLogfile = /var/www/domains/www.itsmydomain.com/logs/access.log
ErrorLogfile = /var/www/domains/www.itsmydomain.com/logs/error.log
}

VirtualHost {
Hostname = www.anotherdomain.com
WebsiteRoot = /var/www/domains/www.anotherdomain.com/htdocs
RequiredBinding = BIND4
StartFile = index.html
AccessLogfile = /var/www/domains/www.anotherdomain.com/logs/access.log
ErrorLogfile = /var/www/domains/www.anotherdomain.com/logs/error.log
}
Hugo Leisink
7 June 2012, 14:08
Correct. But I don't see why you want the BindingID / RequiredBinding construction. What's the use of it?
Gary
7 June 2012, 15:19
It was my (incorrect) assumption I need the BindingID/RequiredBinding to specify which domain belongs to which IP.
Hugo Leisink
7 June 2012, 15:33
Ok, np. Does the provided solution work for you?
Gary
7 June 2012, 16:35
Yes, thank you!

I much prefer Hiawatha to Apache (which I never liked). And now that Hiawatha has reverse proxy functionality, I don't need to maintain another web server (nginx).

Thank you again for Hiawatha and for your technical support!!
This topic has been closed.