# Infinite loop when using haproxy

**URL:** <https://forum.ghost.org/t/infinite-loop-when-using-haproxy/9061>\
**Category:** Developer help\
**Created:** [September 13, 2019, 2:30pm UTC](https://forum.ghost.org/t/infinite-loop-when-using-haproxy/9061 "2019-09-13T14:30:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![svikashk](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/svikashk/32/580_2.png) [@svikashk](https://forum.ghost.org/u/svikashk)\
**Post date:** [September 13, 2019, 2:30pm UTC](https://forum.ghost.org/t/infinite-loop-when-using-haproxy/9061/1 "2019-09-13T14:30:55Z")

</div>

Hi there,

We are running ghost behind haproxy. Haproxy is used for terminating ssl and we are forwarding the request to ghost. The following is our haproxy config.

```auto
global
  log 127.0.0.1 local0 notice
  maxconn 2048
  user haproxy
  group haproxy
defaults
  log global
  mode http
  option httplog
  option dontlognull
  retries 3
  option redispatch
  option forwardfor
  option http-server-close
  timeout connect 5000
  timeout client 10000
  timeout server 10000
backend ghost
  balance roundrobin
  option forwardfor
  http-request set-header X-Forwarded-Port %[dst_port]
  http-request add-header X-Forwarded-Proto https
  server ghost <ghost-ip>
frontend http-in
  bind :80
  bind :443 ssl crt <crt>
  use_backend ghost if { path_beg /blog }
  default_backend api

```

**Our setup:**

- Ghost-CLI version: 1.11.0
- Ghost version: 2.31.0

In ghost, our config url is `https://<our-site>/blog`.

This setup results in an infinite redirect to `https://<our-site>/blog`.

But it works when our config url is `http://<our-site>/blog`.

What is that we are missing out in haproxy config or is there something else that we are missing?

---

<div class="post-metadata">

**Author:** ![rodrigoSyscop](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/rodrigosyscop/32/14925_2.png) [@rodrigoSyscop](https://forum.ghost.org/u/rodrigoSyscop)\
**Post date:** [September 5, 2021, 6:22pm UTC](https://forum.ghost.org/t/infinite-loop-when-using-haproxy/9061/2 "2021-09-05T18:22:27Z")

</div>

I’m also having this exactly same issue.

---

<div class="post-metadata">

**Author:** ![rodrigoSyscop](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/rodrigosyscop/32/14925_2.png) [@rodrigoSyscop](https://forum.ghost.org/u/rodrigoSyscop)\
**Post date:** [September 5, 2021, 7:02pm UTC](https://forum.ghost.org/t/infinite-loop-when-using-haproxy/9061/3 "2021-09-05T19:02:21Z")

</div>

I was able to fix this by setting the following in my haproxy’s frontend:

```auto
    http-request redirect scheme https unless { ssl_fc }
    http-request set-header X-Forwarded-Proto https if { ssl_fc }
    http-request set-header X-Forwarded-Proto http if !{ ssl_fc }

```

I also had to set this on nginx:

```auto
server {
    listen 8080;
    listen [::]:8080;

    server_name myalwesomesite.com;
    root /home/myalwesomesite/ghost_site/system/nginx-root; # Used for acme.sh SSL verification (https://acme.sh)

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        #proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto; 
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:2368;
        
    }

    location ~ /.well-known {
        allow all;
    }

    client_max_body_size 50m;
}

```

Ref.: [Mapping Headers in Nginx | Servers for Hackers](https://serversforhackers.com/c/nginx-mapping-headers)
