Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to enable a way for developers/testers to access specific servers behind a HAProxy, to facilitate testing. The way we do it right now is by accessing the server's hostname (e.g. server1.mywebsite.com) directly, but we've seen differences relating to virtual hosts, ssl, etc... I'd like to set a cookie or a query string arg or something so I can force a server to be used...

something like www.mywebsite.com (with cookie super_secret_cookie=server1) or www.mywebsite.com?super_secret_key=server1

To be clear, this would be used by internal users, not the public in general.

Ideas?

Edit: I'm using version 1.3.12

share|improve this question

2 Answers 2

I guess your question is outdated, but for those who come after, heres how I did it:

we define some acl:

frontend http-in
acl has_server1_cookie  hdr_beg(cookie) server1

use_backend single_server1_backend if has_server1_cookie

and of course we have to define that backend:

backend single_server1_backend 
server server1.mywebsite.com 192.168.1.123:80 maxconn 32 check

we can even add to the backend section the following

reqadd backend:\ server1

which will tell haproxy to add to each request dispatched to server1 a http header

backend: server1

which is nice and eays for checking just to be sure that it actually works..

share|improve this answer

You're unnecessarily complicating things. If you've got "differences relating to virtual hosts, ssl, etc" then FIX THOSE. When you start bodgying things up with cookies and query string args (are you going to modify your application to persist that query string arg through every request? Even more complications...) you just make things more complicated, which means more difficult to debug, more likely that it'll be accidentally broken by an unrelated change, and generally you just make life difficult for yourself and everyone else.

So, take a step back, and instead of asking about implementing a half-baked solution you've come up with, ask a question about how to solve your problem. "We have an haproxy, and would like to access the machines directly, but when we do this we get (describe difference with virtual hosts)."

My guess for your vhosts problem is that they're not setup to accept the machine's name directly, which is trivial to fix -- an extra entry in server_name (or a new ServerAlias) gets you away there. For SSL, that's a smidge trickier if you're not using a wildcard cert, but since it's only internal users, ignoring the SSL warning is a (semi-)valid solution to the problem -- or you can just run a separate SSL cert for the per-machine stuff (on an internal CA). If you're terminating SSL on the load balancer, stop doing that then.

share|improve this answer

Your Answer

 
discard

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.