Cover of the book Symfony 5: The Fast Track

Symfony 5: The Fast Track is the best book to learn modern Symfony development, from zero to production. +300 pages in full color showing how to combine Symfony with Docker, APIs, queues & async tasks, Webpack, Single-Page Applications, etc.

Buy printed version

New in Symfony 2.3: Use Sub-Networks to configure Trusted Proxies

Dmitrii Chekaliuk

Contributed by
Dmitrii Chekaliuk
in #7735.

Whenever an application is behind some reverse proxies, you need to configure it properly to get the "real" IP address for the client and some other important information about the request.

Configuring the trusted proxies can be done easily from the front controller:


Or via the configuration (as of 2.3):

    trusted_proxies: ['']

The setTrustedProxies() method works with IPv4 and IPv6 addresses, and as of Symfony 2.3, it also supports the CIDR notation, which is really useful when you have one or more reverse proxies with dynamic IP addresses (like for instance the Elastic Load Balancers of Amazon EC2). And of course, you can mix-and-match all notations in one call:

Request::setTrustedProxies(array('', '', 'fc00::/7'));

That might seem like a small addition, but one that is really useful when managing big websites.

Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.

New in Symfony 2.3: Use Sub-Networks to configure Trusted Proxies

Tweet this


interesting possibility
Symfony really moves in the right direction !

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.