# Change http to https and proxy for remote http server does not work

**URL:** <https://discourse.haproxy.org/t/change-http-to-https-and-proxy-for-remote-http-server-does-not-work/12132>\
**Category:** Help!\
**Created:** [March 15, 2026, 4:58pm UTC](https://discourse.haproxy.org/t/change-http-to-https-and-proxy-for-remote-http-server-does-not-work/12132 "2026-03-15T16:58:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mec](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@mec](https://discourse.haproxy.org/u/mec)\
**Post date:** [March 15, 2026, 4:58pm UTC](https://discourse.haproxy.org/t/change-http-to-https-and-proxy-for-remote-http-server-does-not-work/12132/1 "2026-03-15T16:58:39Z")

</div>

Hi,

I try to do the following:

- incoming http request on IP1 on port 5090 is redirected to become https on IP1
- content is delivered from backend server with IP2 via htttp

HAProxy is running on IP1 and apache is running on IP2, configured for http listening on port 5090.

My HAProxy looks like:

```auto
global
    log /dev/log local0 debug

    #chroot /var/lib/haproxy
    pidfile /var/run/haproxy.pid
    maxconn 4000
    user haproxy
    group haproxy
    daemon

    stats socket /var/lib/haproxy/stats
    ssl-default-bind-ciphers PROFILE=SYSTEM
    ssl-default-server-ciphers PROFILE=SYSTEM

defaults
    mode http
    log global
    option httplog
    option dontlognull
    option http-server-close
    option forwardfor       
    option redispatch
    retries 3
    timeout http-request 10s
    timeout queue 1m
    timeout connect 10s
    timeout client 1m
    timeout server 1m
    timeout http-keep-alive 10s
    timeout check 10s
    maxconn 3000

frontend main
    mode http
    bind *:5090
    http-request redirect scheme https code 302

frontend main2
    bind *:443 ssl crt /etc/certs/cert.pem
    default_backend my-backend

backend my-backend
   mode http
   server server1 <IP2>:5090

```

However, that doesn’t work as I hoped. What happens is that an incoming http request on port 5090 is changed to become https, but the port 5090 stays in the URL, e.g.

http://:5090/path/to/index becomes https://:5090/path/to/index

which then of course does not work and results in:

`main main/ -1/-1/-1/-1/0 400 0 - - PR-- 1/1/0/0/0 0/0 “” `

When I remove the redirect in “frontend main” and let it stay plain http, then the content is delivered from “my-backend”.

How do I need to change the frontend part to have incoming http requests on port 5090 changed to https (port 443) and then have content delivered from the http endpoint on IP2?

I already tried different redirect codes, but always with the same result.

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [March 15, 2026, 7:35pm UTC](https://discourse.haproxy.org/t/change-http-to-https-and-proxy-for-remote-http-server-does-not-work/12132/2 "2026-03-15T19:35:15Z")

</div>

`redirect scheme https` will just use the Host header and redirect to https, which when using a non-standard HTTP port will contain the port.

In this case you will have to manually specify the destination with something like `redirect prefix https://IP1`

---

<div class="post-metadata">

**Author:** ![mec](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@mec](https://discourse.haproxy.org/u/mec)\
**Post date:** [March 15, 2026, 8:02pm UTC](https://discourse.haproxy.org/t/change-http-to-https-and-proxy-for-remote-http-server-does-not-work/12132/3 "2026-03-15T20:02:25Z")

</div>

Thanks - that works!
