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

Skip to content

Commit bd63f26

Browse files
committed
[symfony#2857] Fixing a few minor errors, adding more details, and using the non-deprecated trusted_proxies config in forwarded headers docs
1 parent b3c76a5 commit bd63f26

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

cookbook/cache/varnish.rst

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,20 @@ that will invalidate the cache for a given resource:
176176
}
177177
}
178178
179-
Routing
180-
------------------
179+
Routing and X-FORWARDED Headers
180+
-------------------------------
181181

182182
To ensure that the Symfony Router generates urls correctly with Varnish,
183-
proper ```X-Forwarded``` headers must be added. Headers depend on how you
184-
have configured hosts and ports for the web server and Varnish but this
185-
example should work if the web server is using the same IP as Varnish but
186-
a different port (e.g. 8080).
183+
proper ```X-Forwarded``` headers must be added so that Symfony is aware of
184+
the original port number of the request. Exactly how this is done depends
185+
on your setup. As a simple example, Varnish and your web server are on the
186+
same machine and that Varnish is listening on one port (e.g. 80) and Apache
187+
on another (e.g. 8080). In this situation, Varnish should add the ``X-Forwarded-Port``
188+
header so that the Symfony application knows that the original port number
189+
is 80 and not 8080.
190+
191+
If this header weren't set properly, Symfony may append ``8080`` when generating
192+
absolute URLs:
187193

188194
.. code-block:: text
189195
@@ -197,8 +203,9 @@ a different port (e.g. 8080).
197203
198204
.. note::
199205

200-
Remember to set ``framework.trust_proxy_headers: true`` in the Symfony
201-
configuration for this to work.
206+
Remember to configure :ref:`framework.trusted_proxies<reference-framework-trusted-proxies>`
207+
in the Symfony configuration so that Varnish is seen as a trusted proxy
208+
and the ``X-Forwarded-`` headers are used.
202209

203210
.. _`Edge Architecture`: http://www.w3.org/TR/edge-arch
204211
.. _`GZIP and Varnish`: https://www.varnish-cache.org/docs/3.0/phk/gzip.html

reference/configuration/framework.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ services related to testing your application (e.g. ``test.client``) are loaded.
9494
This setting should be present in your ``test`` environment (usually via
9595
``app/config/config_test.yml``). For more information, see :doc:`/book/testing`.
9696

97+
.. _reference-framework-trusted-proxies:
98+
9799
trusted_proxies
98100
~~~~~~~~~~~~~~~
99101

0 commit comments

Comments
 (0)