# Configure virtualhost on haproxy

**URL:** <https://discourse.haproxy.org/t/configure-virtualhost-on-haproxy/3992>\
**Category:** Help!\
**Created:** [July 2, 2019, 2:31am UTC](https://discourse.haproxy.org/t/configure-virtualhost-on-haproxy/3992 "2019-07-02T02:31:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![newbie91](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/newbie91/32/860_2.png) [@newbie91](https://discourse.haproxy.org/u/newbie91)\
**Post date:** [July 2, 2019, 2:31am UTC](https://discourse.haproxy.org/t/configure-virtualhost-on-haproxy/3992/1 "2019-07-02T02:31:36Z")

</div>

hallo, can someone help me? I have problem with multiple website that I hosted on my backend server, I have 2 backend server as follow :

1. server1.local 192.168.10.100
2. server2.local 192.168.11.100

and my haproxy server is : server3.local 192.168.12.10

my dirrectory web I put it on both backend server :

1. server1 /var/www/html/nextcloud
2. server2 /var/www/html/nextcloud

I wanto configure load balancing and HA in HAProxy server, but not working, my haproxy.cfg is as follow :

frontend LB  
bind \*:80  
reqadd X-Forwarded-Proto:\ http  
#default\_backend LB

# Define hosts

acl host\_cacti hdr(host) -i dakusoft.cacti  
acl host\_osticket hdr(host) -i dakusoft.osticket  
acl host\_nextcloud hdr(host) -i dakusoft.nextcloud

## figure out which one to use

use\_backend cacti\_cluster if host\_cacti  
use\_backend osticket\_cluster if host\_osticket  
use\_backend nextcloud\_cluster if host\_nextcloud

backend cacti\_cluster  
balance leastconn  
option httpclose  
rspadd X-Frame-Options:\ SAMEORIGIN  
option forwardfor  
cookie JSESSIONID prefix  
server server1 server1.local:80 cookie server1 check  
#server server2 server2.local:80 cookie server2 check

# backend nextcloud\_cluster balance leastconn rspadd X-Frame-Options:\ SAMEORIGIN option httpclose option forwardfor cookie JSESSIONID prefix server server1 server1.local:80 cookie server1 check server server2 server2.local:80 cookie server2 check

and this is virtualhost configuration on backend that I created on both of backend server

---

<div class="post-metadata">

**Author:** ![ciprian.craciun](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/ciprian.craciun/32/722_2.png) [@ciprian.craciun](https://discourse.haproxy.org/u/ciprian.craciun)\
**Post date:** [July 2, 2019, 5:54am UTC](https://discourse.haproxy.org/t/configure-virtualhost-on-haproxy/3992/2 "2019-07-02T05:54:13Z")

</div>

First of all, please note that you can use Markdown to properly format the configuration as a snippet. (As it stands now, it is extremely hard to follow.)

Now regarding the actual setup, it is a little bit unclear if both backend servers host all the three domains? (If so, then you don’t need three backends, just one for the whole cluster;  
else indeed you need three backends in which you put only the relevant servers.)

Regardless of the above observation, the HAProxy configuration seems OK (at a first glance), thus I would say it might be a configuration issue on the backend server themselves. (Do they properly respond to these domains when you put their IP’s in `/etc/hosts` for the target domains?)

---

<div class="post-metadata">

**Author:** ![newbie91](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/newbie91/32/860_2.png) [@newbie91](https://discourse.haproxy.org/u/newbie91)\
**Post date:** [July 2, 2019, 10:47am UTC](https://discourse.haproxy.org/t/configure-virtualhost-on-haproxy/3992/3 "2019-07-02T10:47:29Z")

</div>

thanks for your reply. yes, both backend servers host all the three domains… all my backend server has reachable each one other, I already configure it on etc/hosts. and now the problem has been solved… the problem is in the “cookie JSESSIONID prefix” line which I added in the backend configuration.I deleted this line and restart haproxy and now working properly with virtual host. you said only 1 backend for whole cluster, configuratio0n that I made above is from tutorials on internet for configuration multiple domain using ACL.can you to give me example config for for only 1 backend for whole cluster in multiple domain?

---

<div class="post-metadata">

**Author:** ![ciprian.craciun](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/ciprian.craciun/32/722_2.png) [@ciprian.craciun](https://discourse.haproxy.org/u/ciprian.craciun)\
**Post date:** [July 2, 2019, 12:11pm UTC](https://discourse.haproxy.org/t/configure-virtualhost-on-haproxy/3992/4 "2019-07-02T12:11:29Z")

</div>

> [@newbie91](#):
>
> you said only 1 backend for whole cluster, configuratio0n that I made above is from tutorials on internet for configuration multiple domain using ACL.can you to give me example config for for only 1 backend for whole cluster in multiple domain?

If all of the servers have the same role (i.e. they can replace one-another), and if you don’t serve other domains with this HAProxy instance (except those already handled by the current servers), then you can leave only one of those backends, and use it with `default_backend`; moreover you don’t need any ACL statements.

Basically you’re using HAProxy just as a load-balancer. (As opposed to an “HTTP-router” as you were with those ACL’s.)

(The tutorials you’ve seen had perhaps different servers in each backend. Or perhaps they did something more complex, like “mangling” HTTP traffic in each backend based differently for each domain.)

In the end it doesn’t matter much if you split the domains in three backends or a single one, except:

- having different backends could allow you to gather some “primitive” statistics about the load;
- if you consider fiddling with the various load fine-tuning parameters (like queue length, max concurrent sessions, etc.), note that HAProxy sees each server in the three backends as different ones, thus it might “lie” about the total capacity you have at your disposal;
