Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      June 4, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 4, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 4, 2025

      Smashing Animations Part 4: Optimising SVGs

      June 4, 2025

      I test AI tools for a living. Here are 3 image generators I actually use and how

      June 4, 2025

      The world’s smallest 65W USB-C charger is my latest travel essential

      June 4, 2025

      This Spotlight alternative for Mac is my secret weapon for AI-powered search

      June 4, 2025

      Tech prophet Mary Meeker just dropped a massive report on AI trends – here’s your TL;DR

      June 4, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Beyond AEM: How Adobe Sensei Powers the Full Enterprise Experience

      June 4, 2025
      Recent

      Beyond AEM: How Adobe Sensei Powers the Full Enterprise Experience

      June 4, 2025

      Simplify Negative Relation Queries with Laravel’s whereDoesntHaveRelation Methods

      June 4, 2025

      Cast Model Properties to a Uri Instance in 12.17

      June 4, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      My Favorite Obsidian Plugins and Their Hidden Settings

      June 4, 2025
      Recent

      My Favorite Obsidian Plugins and Their Hidden Settings

      June 4, 2025

      Rilasciata /e/OS 3.0: Nuova Vita per Android Senza Google, Più Privacy e Controllo per l’Utente

      June 4, 2025

      Rilasciata Oracle Linux 9.6: Scopri le Novità e i Miglioramenti nella Sicurezza e nelle Prestazioni

      June 4, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Managing Proxy Trust in Laravel Applications

    Managing Proxy Trust in Laravel Applications

    January 4, 2025

    Managing Proxy Trust in Laravel Applications

    When deploying Laravel applications behind load balancers or reverse proxies, proper configuration of the TrustProxies middleware ensures correct handling of client information and HTTPS detection.

    use IlluminateHttpRequest;
    
    // Basic proxy configuration
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->trustProxies(at: [
            '10.0.0.0/8',
            '172.16.0.0/12'
        ]);
    });
    

    Let’s explore a practical example of configuring your application for various cloud environments:

    <?php
    
    use IlluminateHttpRequest;
    
    ->withMiddleware(function (Middleware $middleware) {
        // Cloud environment detection
        $environment = env('APP_ENV');
        
        switch ($environment) {
            case 'production':
                // AWS ELB Configuration
                $middleware->trustProxies(
                    at: '*',
                    headers: Request::HEADER_X_FORWARDED_AWS_ELB
                );
                break;
                
            case 'staging':
                // Digital Ocean Configuration
                $middleware->trustProxies(
                    at: '*',
                    headers: Request::HEADER_X_FORWARDED_FOR |
                        Request::HEADER_X_FORWARDED_HOST |
                        Request::HEADER_X_FORWARDED_PORT |
                        Request::HEADER_X_FORWARDED_PROTO
                );
                break;
                
            default:
                // Local/Development Configuration
                $middleware->trustProxies(
                    at: ['127.0.0.1', '::1'],
                    headers: Request::HEADER_X_FORWARDED_FOR |
                        Request::HEADER_X_FORWARDED_PROTO
                );
        }
    });
    

    The TrustProxies middleware ensures your application correctly handles client information when operating behind load balancers or reverse proxies.


    The post Managing Proxy Trust in Laravel Applications appeared first on Laravel News.

    Join the Laravel Newsletter to get all the latest
    Laravel articles like this directly in your inbox.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleGary Marcus – Taming Silicon Valley | Starmus Highlights
    Next Article How to Use JavaScript Streams for Efficient Asynchronous Requests

    Related Posts

    Security

    HPE StoreOnce Faces Critical CVE-2025-37093 Vulnerability — Urges Immediate Patch Upgrade

    June 4, 2025
    Security

    Google fixes Chrome zero-day with in-the-wild exploit (CVE-2025-5419)

    June 4, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Run multiple CLI commands locally at once with Solo for Laravel

    Development

    ZDNET joins CNET Group to award the Best of CES, and you can submit your entry now

    Development

    (non) recensione CachyOS

    Linux

    The CDKeys 2024 Game Awards: Who’s winning and more importantly, what’s discounted for us?

    News & Updates

    Highlights

    Stateless decision making

    May 10, 2025

    Do you ever feel like your brain is full and there’s so much going on…

    CVE-2025-2777 – SysAid On-Prem XXE Vulnerability

    May 7, 2025

    Inspirational Websites Roundup #61

    June 18, 2024

    Critical Langflow Vulnerability (CVE-2025-3248) Actively Exploited, Warns CISA

    May 7, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.