-1

I am using apache 2.4 and would like to create multiple vhosts. The vhosts should be matched based on the X-Forwarded-Host header, instead of the Host header.

Unfortunatly I could not find anything in the documentation. Is this behaviour possible? If yes, how?

To further clarify my problem: The documentation of the ServerName directive states

If you are using name-based virtual hosts, the ServerName inside a section specifies what hostname must appear in the request's Host: header to match this virtual host.

I am trying to achive the same behaviour, but based on X-Forwarded-Host

12
  • could you elaborate on your use-case?
    – criztovyl
    Sep 9, 2022 at 19:56
  • @criztovyl: the server is behind a cloud based reverse proxy, handling caching, tls offloading and other things. Since it is an L7 appliance it makes a new http request. The host is always set to the host the server as known to the reverse proxy. the original host name is set as x-forwarded-host.
    – stena
    Sep 9, 2022 at 20:12
  • Hace you checked whether the reverse proxy allows you to set the outgoing host header?
    – criztovyl
    Sep 9, 2022 at 20:16
  • 1975274943oting to close. This is not showing no best practices, but seems to show total lack of basic knowledge and effort to use a search engine. I am NOT an apache person, but out of interest I typed "apache x-forwarded-host" into google and... found httpd.apache.org/docs/2.4/mod/mod_proxy.html Using google with "apache mod_proxy x-forwarded-host" points me to confluence.atlassian.com/conf59/… among other things. This site is not meant to be a first utility, one has to show effort first - this totally seems to lack.
    – TomTom
    Sep 9, 2022 at 20:32
  • @TomTom what you found is for proxy, the question is about virtual hosts.
    – criztovyl
    Sep 9, 2022 at 20:44

1 Answer 1

0

After the discussions in the comment, I assume it seems to be impossible to do out of the box.

The easiest workaround seems to enforcing Host header preservation outside the webserver.

In case it is impossible to change at the L7 appliance setting the Host header, an option would be to add another reverse proxy, with the sole purpose, writing the XFH header to the Host header. This could be actually another apache2 httpd (recycling @Tomtom's comment here), but there are probably solutions with a smaller footprint for this purpose.

Another option to investigate would be to write a dedicated mod for Apache, while I am not sure if it is a good idea to swap the detected server name since it seems to be tied very deeply in the source.

What definitly did not work was trying to override the host header using apache config directives using RequestHeader set Host .... It changed the header, but did not have effect on vhost selection.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .