Laravel Trusted Proxies
Published on by Eric L. Barnes
Laravel Trusted Proxy is a package designed to help you when running Laravel behind a proxy.
Some common problems when you are utilizing proxies, like a load balancer, are:
- Redirects and PHP generated URLs may be fallacious. The address, protocol and/or port.
- Unique sessions might not be created for each user, leading to possible access to incorrect accounts, or an inability for a user to log in at all.
- Logging or other data-collection processes data may appear to come from one location (the proxy itself) leaving you with no way to distinguish between traffic/actions taken by individual clients.
Laravel doesn’t include configuration for this, but because it relies on Symfony for Requests and Responses you can utilize it to handle proxies.
This is where the Trusted Proxy package comes in. It handles the setup of checking the request for a trusted IP address and then allows the headers to be passed through. If it’s not from a trusted IP then it will ignore it.
Trusted Proxy takes advantage of the new Middleware feature in Laravel 5 and can be installed easily. It comes complete with a config file and a thorough documentation.
Eric is the creator of Laravel News and has been covering Laravel since 2012.