Skip to content

Commit 07e82c4

Browse files
committed
feature #5382 Added support for standard Forwarded header (tony-co, javiereguiluz)
This PR was merged into the 2.3 branch. Discussion ---------- Added support for standard Forwarded header | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.7+ | Fixed tickets | - This PR finishes the work made by @tony-co in #4266. Commits ------- 8928049 Fixed a minor grammar issue 319c081 Fixed a minor grammar issue ac3689b Added support for standard Forwarded header d452137 Added support for standard Forwarded header
2 parents 12bbd08 + 8928049 commit 07e82c4

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

cookbook/request/load_balancer_reverse_proxy.rst

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ an AWS Elastic Load Balancer) or a reverse proxy (e.g. Varnish for
77

88
For the most part, this doesn't cause any problems with Symfony. But, when
99
a request passes through a proxy, certain request information is sent using
10-
special ``X-Forwarded-*`` headers. For example, instead of reading the ``REMOTE_ADDR``
11-
header (which will now be the IP address of your reverse proxy), the user's
12-
true IP will be stored in an ``X-Forwarded-For`` header.
10+
either the standard ``Forwarded`` header or non-standard special ``X-Forwarded-*``
11+
headers. For example, instead of reading the ``REMOTE_ADDR`` header (which
12+
will now be the IP address of your reverse proxy), the user's true IP will be
13+
stored in a standard ``Forwarded: for="..."`` header or a non standard
14+
``X-Forwarded-For`` header.
15+
16+
.. versionadded:: 2.7
17+
``Forwarded`` header support was introduced in Symfony 2.7.
1318

1419
If you don't configure Symfony to look for these headers, you'll get incorrect
1520
information about the client's IP address, whether or not the client is connecting
@@ -57,9 +62,9 @@ the IP address ``192.0.0.1`` or matches the range of IP addresses that use
5762
the CIDR notation ``10.0.0.0/8``. For more details, see the
5863
:ref:`framework.trusted_proxies <reference-framework-trusted-proxies>` option.
5964

60-
That's it! Symfony will now look for the correct ``X-Forwarded-*`` headers
61-
to get information like the client's IP address, host, port and whether or
62-
not the request is using HTTPS.
65+
That's it! Symfony will now look for the correct headers to get information
66+
like the client's IP address, host, port and whether the request is
67+
using HTTPS.
6368

6469
But what if the IP of my Reverse Proxy Changes Constantly!
6570
----------------------------------------------------------
@@ -93,9 +98,14 @@ other information.
9398
My Reverse Proxy Uses Non-Standard (not X-Forwarded) Headers
9499
------------------------------------------------------------
95100

96-
Most reverse proxies store information on specific ``X-Forwarded-*`` headers.
97-
But if your reverse proxy uses non-standard header names, you can configure
101+
Although `RFC 7239`_ recently defined a standard ``Forwarded`` header to disclose
102+
all proxy information, most reverse proxies store information in non-standard
103+
``X-Forwarded-*`` headers.
104+
105+
But if your reverse proxy uses other non-standard header names, you can configure
98106
these (see ":doc:`/components/http_foundation/trusting_proxies`").
107+
99108
The code for doing this will need to live in your front controller (e.g. ``web/app.php``).
100109

101110
.. _`security groups`: http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/using-elb-security-groups.html
111+
.. _`RFC 7239`: http://tools.ietf.org/html/rfc7239

0 commit comments

Comments
 (0)