Nginx – Haproxy rewrite host but send original one to servers

haproxyload balancingnginx

Currently, I have nginx > 25 x nginx + fcgi

The main nginx, does the load balancing and each virtualhost listens to a different ip (different products).

some of the ips receive different hostnames, and they get rewritten back to the backend servers like:

http://some-random-url.com/path

GET /path HTTP/1.1

Host: app1

X-Original-Host: some-random-url.com

X-Forwarded-For: 12.34.56.78

….

We're currently replacing the main proxy with haproxy (better load balancing algorithms) but I can't figure out how to append the original host. (I can't find any documentation on variables like nginx's $host).

I can rewrite the url like:

reqirep ^Host: Host:\ app1

but "app1" still requires the original hostname to do business logic.

I thought about running each app on a different port but the problem is that I want nginx's httpchk to work for all the backend servers, and doing one backend per app means 10 apps x 10 checks = 10 checks per second to each backend (unless the log data lied).

Anyone have an Idea?

Best Answer

Just leave the Host header alone - HAProxy doesn't molest it normally, so if you leave it alone it will be passed to your application servers.