# Difficulty using haproxy with apache2 virtualhost

**URL:** <https://discourse.haproxy.org/t/difficulty-using-haproxy-with-apache2-virtualhost/7741>\
**Category:** Help!\
**Created:** [June 11, 2022, 7:46am UTC](https://discourse.haproxy.org/t/difficulty-using-haproxy-with-apache2-virtualhost/7741 "2022-06-11T07:46:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liso](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/liso/32/1711_2.png) [@Liso](https://discourse.haproxy.org/u/Liso)\
**Post date:** [June 11, 2022, 7:46am UTC](https://discourse.haproxy.org/t/difficulty-using-haproxy-with-apache2-virtualhost/7741/1 "2022-06-11T07:46:04Z")

</div>

I’m trying to redirect user to different server based on domain hostname. It seems so easy, but I have spent a week and haven’t found a solution. This is my `/etc/haproxy/haproxy.cfg`.

```auto
frontend t-proxy
    bind 0.0.0.0:80
    mode http
    
    acl url_ex hdr(host) -i my.domain.xyz
    use_backend ex if url_ex
    
backend ex
	mode http
	balance roundrobin
	server vps12 (IP_ADDRESS_A):80 check
	server vps3 (IP_ADDRESS_B):80 backup

```

This is virtualhost on `vps12` and `vps3` (both have same copies).

```auto
<VirtualHost *:443>
    ServerAdmin user@mail.net
    ServerName my.domain.xyz
    DocumentRoot /var/www/domain

    <Directory />
         Options FollowSymLinks
         AllowOverride None
    </Directory>

    SSLEngine on
	SSLCertificateFile /opt/acme-cert/my.domain.xyz/cert.pem
	SSLCertificateKeyFile /opt/acme-cert/my.domain.xyz/site.key
	SSLCertificateChainFile /opt/acme-cert/my.domain.xyz/fullchain.cer
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<VirtualHost *:80>
    ServerName my.domain.xyz
    Redirect permanent / https://my.domain.xyz/
</VirtualHost>

```

But when I type `my.domain.xyz` on browser, it took so long to load and I’m presented with this.

 ![screen91](https://us1.discourse-cdn.com/flex016/uploads/haproxy/original/2X/7/78bb8b6e5819dc0dcec3914694a3b95a61210043.jpeg)

Checking `haproxy.log` yield this, I’m not sure if its useful.

```auto
Jun 11 08:30:44 vps-proxy haproxy[7511]: (CLIENT_IP):34498 [11/Jun/2022:08:30:44.594] t-proxy ex/vps12 0/0/1/1/2 301 423 - - ---- 1/1/0/0/0 0/0 "GET / HTTP/1.1"

```

Anyone can help troubleshooting this problem ? I feel like I’m missing the obvious here.

---

<div class="post-metadata">

**Author:** ![Markus](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@Markus](https://discourse.haproxy.org/u/Markus)\
**Post date:** [June 14, 2022, 9:18am UTC](https://discourse.haproxy.org/t/difficulty-using-haproxy-with-apache2-virtualhost/7741/2 "2022-06-14T09:18:54Z")

</div>

one guess:

you are connection to haproxy with port :80 (http). then there will be a forward to vp12. apache force a redirect to [https://my.domain.xyz](https://my.domain.xyz). what ip address i do get for my.domain.xyz? ip address of haproxy? if this i your complete haproxy.cfg that you haven’t configured https part. you can also do a http-\>https redirect straight in haproxy, see

> **[Redirect HTTP to HTTPS with HAProxy - HAProxy Technologies](https://www.haproxy.com/de/blog/redirect-http-to-https-with-haproxy/)**
>
> Use the HAProxy load balancer to redirect users from HTTP to HTTPS automatically.
