代码之家  ›  专栏  ›  技术社区  ›  Chuck Le Butt

Laravel通过HTTP服务资产,而不是使用AWS的HTTPS

  •  4
  • Chuck Le Butt  · 技术社区  · 6 年前

    {{ asset() }} {{ route() }}

    我使用的是带有负载平衡弹性Beanstalk应用程序的AWS。

    APP_URL 正确设置为https,我理解我可以使用 secure_asset forceScheme 但是,我不必在以前的项目中这样做,我想知道为什么。

    2 回复  |  直到 6 年前
        1
  •  5
  •   Chuck Le Butt    6 年前
    类信任代理扩展中间件 /** */ /** * */

    https://laravel.com/docs/5.6/requests#configuring-trusted-proxies

    enter image description here

    app/Http/Middleware/TrustProxies.php 以下内容:

    class TrustProxies extends Middleware
    {
        /**
         * The trusted proxies for this application.
         *
         * @var array
         */
        protected $proxies = '*';
    
        /**
         * The headers that should be used to detect proxies.
         *
         * @var int
         */
        protected $headers = Request::HEADER_X_FORWARDED_AWS_ELB;
    }
    

        2
  •  0
  •   Gothiquo    6 年前

    secure_asset 就是你要找的。

    <link href="{{ secure_asset('assets/mdi/css/materialdesignicons.min.css') }}" media="all" rel="stylesheet" type="text/css" />
    

    更新:


    <?php
    
    namespace App\Providers;
    
    use Illuminate\Support\ServiceProvider;
    
    class AppServiceProvider extends ServiceProvider
    {
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        if(env('APP_ENV') == 'production') {
            \URL::forceScheme('https');
        }
    }
    
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
    }