Haproxy + Apache + Virtual Hosts -> Wrong Host Is Displayed

Home » CentOS » Haproxy + Apache + Virtual Hosts -> Wrong Host Is Displayed
CentOS 1 Comment


I hope my question is not off-topic here.

On CentOS 7.2.1511 I have installed:

The /etc/haproxy/haproxy.cfg binds HAProxy to ports 80 and 443 and accepts HTTPS to slova.de:

mode http
option http-server-close
option forwardfor except
option redispatch
…. frontend public
bind ssl crt /etc/pki/tls/certs/slova.de.pem
reqidel ^X-Forwarded-Proto:
reqidel ^X-Forwarded-For:
reqadd X-Forwarded-Proto:\ https if { ssl_fc }
option forwardfor
default_backend apache

backend apache
server domain

The /etc/httpd/conf/httpd.conf binds Apache to port 8080 and serves several WordPress sites:


DocumentRoot /var/www/html/afarber.de
ServerName afarber.de
ErrorLog logs/afarber.de/error_log
CustomLog logs/afarber.de/access_log common

DocumentRoot /var/www/html/ruhrgebietsingle.de
ServerName ruhrgebietsingle.de
ErrorLog logs/ruhrgebietsingle.de/error_log
CustomLog logs/ruhrgebietsingle.de/access_log common

DocumentRoot /var/www/html/bukvy.de
ServerName bukvy.de
ErrorLog logs/bukvy.de/error_log
CustomLog logs/bukvy.de/access_log common

DocumentRoot /var/www/html/slova.de
ServerName slova.de
ErrorLog logs/slova.de/error_log
CustomLog logs/slova.de/access_log common

When I open http://slova.de or https://www.slova.de they work fine. But when I try to open same URLs with “www.” prepended, the browser displays http://ruhrgebietsingle.de (the 2nd site out of 4)

Why does it happen? I just can not figure it out.

What tool would help here to debug?

Thank you Alex

One thought on - Haproxy + Apache + Virtual Hosts -> Wrong Host Is Displayed

  • Ok, I had to add ServerAlias for each server, didn’t think of it because before I had a mod_rewrite rule to remove the “www.” prefix…