Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c096852

Browse files
TomiSweaverryan
authored andcommitted
Varnish configuration to ensure routing works
1 parent c471fc7 commit c096852

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

cookbook/cache/varnish.rst

+18
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,23 @@ that will invalidate the cache for a given resource:
176176
}
177177
}
178178
179+
Routing
180+
------------------
181+
To ensure Symfony Router generates urls correctly with Varnish, proper ```X-Forwarded``` headers must be added. Headers depend on how you have configured hosts and ports for the web server and Varnish but this example should work if the web server is using the same IP as Varnish but different port (e.g. 8080).
182+
183+
.. code-block:: text
184+
185+
sub vcl_recv {
186+
if (req.http.X-Forwarded-Proto == "https" ) {
187+
set req.http.X-Forwarded-Port = "443";
188+
} else {
189+
set req.http.X-Forwarded-Port = "80";
190+
}
191+
}
192+
193+
.. note::
194+
195+
Remember to set framework.trust_proxy_headers: true for this to work.
196+
179197
.. _`Edge Architecture`: http://www.w3.org/TR/edge-arch
180198
.. _`GZIP and Varnish`: https://www.varnish-cache.org/docs/3.0/phk/gzip.html

0 commit comments

Comments
 (0)