Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Host normalization for certain cases + support X-Forwarded-Host #1238

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from

Conversation

ddanier
Copy link

@ddanier ddanier commented Jul 22, 2016

See #1237

In detail this PR contains two changes:

  1. BUGFIX: As the current VCL for Varnish 4.x contains {{normalize_host}} just after the first cases requests might get handled (see https://github.com/nexcess/magento-turpentine/blob/devel/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl#L124) there are cases in which the Host normalization just does not happen. In this case the backend server will get an invalid Host header and such fail to handle the request. As visible in the VCL (https://github.com/nexcess/magento-turpentine/blob/devel/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl#L121) this is true for all requests using authentication and when caching is disabled.

To fix this issue I moved {{normalize_host}} before if-statement passing unnormalized requests to the backend server.

  1. FEATURE: We currently use Varnish behind an Apache server, but I think the following is true for other frontend proxies as well: The frontend proxy sitting before Varnish might set an additional HTTP header to allow Varnish to use that information for Host detection. This allows us to normalize the Host header based on the original value of it and thus allows us to normalize Host headers for multisite setups. The PR makes the necessary changes to allow such an setup.

In detail:

The reason you need Host normalization:
Frontend-Server (Host=www.domain.com) -> passes request to Varnish on localhost:1234 and sets the Host header accordingly
Varnish (Host=localhost:1234) will now pass the wrong Host header to its backend server -> The backend server will not be able to select the right domain configuration in this case (no Vhost for localhost)

What current normalization does is just ignoring the Host header inside Varnish and just using what is configured in the backend. This way you loose the possibility to have multisite setups, as the Host header will always be "www.domain.com", no matter what.

Now the frontend server may preserve the original Host in some HTTP header, as Apache does. This means:
Frontend-Server (Host=www.domain.com) -> Varnish (Host=localhost:1234, X-Forwarded-Host=www.domain.com) -> Backend Server (Host=…)

Now using X-Forwarded-Host for the backend server Host header will just fix the Host-header problems as fixation does. In addition it allows for multisite setups.

Hope this clarifies things. ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant