Send Content Type Headers to backend server

Problem: My website is loading my .js and .css files as type “text/html”, but only when going through haproxy.

I have a website on Host1, let’s say IP is and that the website is I also have a DNS record for “” pointing to my haproxy server, who then sends these requests to Host1.

When I access the website directly, without going through haproxy, like “”, everything loads correctly. When I access through", the page doesn’t load fully and when I check the browser tools, I see that the server is serving the .css and .js files as type “text/html”.

I presume I have some misconfiguration on my haproxy. How do I force haproxy to not change or to correctly set the content type headers for each file server by the backend?

Here’s a bit of the configuration of my haproxy file:

        mode http
        bind :443 ssl crt /etc/haproxy/certs/my-cert.pem alpn h2,http/1.1
        bind :80
        redirect scheme https code 301 if !{ ssl_fc }

        stick-table type ip size 5k expire 10h
        stick on src
        cookie JSESSIONID prefix

        # HSTS (63072000 seconds)
        http-response set-header Strict-Transport-Security max-age=63072000

        # ACLs for
        acl acl_my-website hdr(host) -i
        use_backend be_my-website if acl_my-website

# backends
backend be_my-website
        mode http
        option httpchk
        http-request set-path /loginpage
        server host_ip:443 check ssl verify none

Thank you for your help.

It seems the problem stems from the directive “http-request set-path /loginpage”. It is apparently removing the rest of the information from the headers sent in the request, so that when it reaches the server it thinks all file types are text/html.
I’ve changed it to http-request set-uri /loginpage if { path_beg -i / } but it’s still doing the same thing. I wonder how I can change the path the website sends the request to, without removing the rest of the information from the header.

Your analysis is incorrect, you are changing the URI so that paths to css and js files are wrong.

You are rewriting a request that comes in from:

/styles/style1.css to /loginpage/styles/style1.css
/js/js1.css to /loginpage/js/js1.css

While the server probably does not know anything about paths like /loginpage/styles/style1.css

The solution is to stop changing the path on haproxy. Perhaps you could explain what you want to achieve with this loginpage rewrite?

Why not redirect instead?

http-request redirect location /loginpage if { path / }