Fixed Host normalization for certain cases + support X-Forwarded-Host #1238
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See #1237
In detail this PR contains two changes:
To fix this issue I moved {{normalize_host}} before if-statement passing unnormalized requests to the backend server.
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. ;-)