52ky 发表于 2022-5-4 09:09:20

如何修复无效请求(不支持的 SSL 请求)

问题
我正在设置我的 laravel 应用程序,每次我运行 phpatisan serve 它都会在 localhost:8000 启动 laravel 开发服务。但是当我在浏览器上打开 locahost 链接时,它会强制 http 到 https 并记录无效请求(不支持的 SSl 请求)。你建议我如何解决这个问题?

我尝试在 .htaccess 文件中将 HTTPS mod 重写规则强制为 http://。

这是命令行
C:\Users\topaz\cashurban>php artisan serve
Laravel development server started: <http://127.0.0.1:8000>
127.0.0.1:60410 Invalid request (Unsupported SSL request)
127.0.0.1:60418 Invalid request (Unsupported SSL request)
127.0.0.1:60419 Invalid request (Unsupported SSL request)
127.0.0.1:60420 Invalid request (Unsupported SSL request)
127.0.0.1:60421 Invalid request (Unsupported SSL request)
127.0.0.1:60423 Invalid request (Unsupported SSL request)
127.0.0.1:60409 : /assets/img/slider-1.jpg
127.0.0.1:60425 Invalid request (Unsupported SSL request)
127.0.0.1:60426 Invalid request (Unsupported SSL request)
127.0.0.1:60427 Invalid request (Unsupported SSL request)
127.0.0.1:60411 : /assets/img/slider-2.jpg
127.0.0.1:60435 Invalid request (Unsupported SSL request)
127.0.0.1:60437 : /assets/img/slider-3.jpg
127.0.0.1:60439 : /assets/img/icon-1-1.png
127.0.0.1:60438 : /assets/img/images/index-Recovereddashboard_03.png
127.0.0.1:60440 : /assets/img/icon-2-1.png
127.0.0.1:60442 : /assets/img/icon-3-1.png
127.0.0.1:60447 Invalid request (Unsupported SSL request)
127.0.0.1:60448 : /assets/img/tor1.png
127.0.0.1:60450 : /assets/img/tor2.png
127.0.0.1:60452 : /assets/img/tor3.png
127.0.0.1:60455 : /assets/img/images/visa.png
127.0.0.1:60453 : /assets/img/images/remita.png
127.0.0.1:60454 : /assets/img/images/master-card.png
127.0.0.1:60460 : /assets/img/images/verve.png
127.0.0.1:60461 : /assets/img/images/indexpartners_11.png
127.0.0.1:60462 : /assets/img/images/bank-branches.png
127.0.0.1:60463 : /assets/img/images/indexpower_03.png
127.0.0.1:60464 : /assets/img/images/paystack.png
127.0.0.1:60465 : /assets/img/images/chams.png
127.0.0.1:60468 Invalid request (Unsupported SSL request)
127.0.0.1:60469 Invalid request (Unsupported SSL request)
这是 .htaccess 文件
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
      Options -MultiViews
    </IfModule>

    RewriteEngine On

    #Force Https

    #RewriteCond %{HTTPS} !=on
    #RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI}


    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d

    #Api Redirect
    RewriteCond %{REQUEST_URI} (.+)/$
    #RewriteRule ^/api$ api.%{REQUEST_URI}


    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* -

    #GZip Compression
    <ifModule mod_gzip.c>
      #mod_gzip_on Yes
      #mod_gzip_dechunk Yes
      #mod_gzip_item_include file .(html?|txt|css|js|php|xml|json|pl)$
      #mod_gzip_item_include handler ^cgi-script$
      #mod_gzip_item_include mime ^text/.*
      #mod_gzip_item_include mime ^application/x-javascript.*
      #mod_gzip_item_exclude mime ^image/.*
      #mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
    </ifModule>

    #php_value auto_prepend_file /home/example_project/public_html/error_handler_slack.php
    php_value auto_prepend_file error_handler_slack.php
</IfModule>
我希望它提供 http://localhost 而不是 https://localhost 因为它当前正在重定向

回答
后来解决了这个问题,以防以后有人遇到类似问题,发现AppServiceProvider类有一个注册方法,注册了一个安全拦截中间件,强制每个http请求都去https。所以我所做的是编写一个 if-else 逻辑,以便仅在生产中允许这样做,因为我的本地主机没有 ssl 证书。

应用内/providers/AppServiceProvider.php

查找 register() 方法,该方法通过检查应用程序是否为本地来实现逻辑。该函数的作用是:检查.env文件中的APP_env变量,如果是局部变量则返回true,所以重新确认设置为局部变量,并确保清除之前所有的配置缓存。
          //check that app is local
       if ($this->app->isLocal()) {
            //if local register your services you require for development
            $this->app->register('Barryvdh\Debugbar\ServiceProvider');
      }else{
            //else register your services you require for production
            $this->app['request']->server->set('HTTPS', true);
      }



页: [1]
查看完整版本: 如何修复无效请求(不支持的 SSL 请求)