Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to know about how Haproxy reacts when I want to make the HTTPS connection over the server. In apache we have aj_proxy to make a ssl connection to tomcat server, so how that functionality can be maintained using stunnel. We are using Haproxy v1.4.13. Our scenario is we want to put the certificates in stunnel and maintain HTTPS session.We are just using plain HTTP at backend. So, when I access the browser validate the certificate but after I login, then it is HTTP again, as it get the content from plain HTTP tomcat servers.

So is there any way that I can make the connection as HTTPS all the time. Below is the config file of stunnel :

sslVersion = all
options = NO_SSLv2
debug = 7
output = /usr/local/etc/stunnel/stunnel.log
chroot = /var/tmp/stunnel

setuid = nobody
setgid = nobody
pid = /

cert = /usr/local/etc/stunnel/stunnel.pem
;Some Performance Tunings

socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
client = noaccept =
connect =
TIMEOUTclose = 0

And Haproxy HTTPS frontend config:

listen https
    mode http
cookie JSESSIONID prefix
balance roundrobin
option forwardfor except
option httpclose
option http-server-close
server S1 cookie server1  maxconn 5000    check
server S2 cookie server2  maxconn 5000    check

Any help will be highly appreciated.

share|improve this question

I'd suggest using nginx as a frontend/reverse proxy instead of stunnel and redirect all traffic from http to https.

I'm not sure if stunnel can handle the http redirects.

share|improve this answer
Thanks. Initially I thought of using nginx but someway messed around with stunnel. Will check it and come back again – panalbish Jun 30 '11 at 15:26
But is it possible that I use nginx infront of Haproxy, as I would like to proxy http request via haproxy ? – panalbish Jun 30 '11 at 15:32
I didn't try nginx, but I tried pound and got the same problem. Since it is only decrypting the SSL and proxying the plain HTTP request to HAproxy. I also tried to make stunnel to run in client and server mode. So that in server mode it do decryption and in client mode encrypted response to be sent to user. Since both client and server stunnel instances were in same machine, I was having problem in binding the port 8080 to accept in client mode. Any body can help me over this isse? – panalbish Jul 8 '11 at 9:12
up vote 0 down vote accepted

Finally I got the solution by stunnel itself. I added RemoteIpValue class in tomcat server.xml configuration. Where I mentioned internalProxies as follow:

... internalProxies="list of IP address of loadbalancers" ...

In my case:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.