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

Posted

技术标签:

【中文标题】如何修复无效请求(不支持的 SSL 请求)【英文标题】:How to fix Invalid request (Unsupported SSL request) 【发布时间】:2019-12-28 06:45:14 【问题描述】:

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

我已尝试在 .htaccess 文件上将 HTTPS 模块重写规则强制为 http://,但它仍然存在。

这是命令行

C:\Users\topaz\cashurban>php artisan serve
Laravel development server started: <http://127.0.0.1:8000>
[Thu Aug 22 23:06:07 2019] 127.0.0.1:60410 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60418 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60419 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60420 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60421 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60423 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60409 [200]: /assets/img/slider-1.jpg
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60425 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60426 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60427 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60411 [200]: /assets/img/slider-2.jpg
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60435 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60437 [200]: /assets/img/slider-3.jpg
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60439 [200]: /assets/img/icon-1-1.png
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60438 [200]: /assets/img/images/index-Recovereddashboard_03.png
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60440 [200]: /assets/img/icon-2-1.png
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60442 [200]: /assets/img/icon-3-1.png
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60447 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60448 [200]: /assets/img/tor1.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60450 [200]: /assets/img/tor2.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60452 [200]: /assets/img/tor3.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60455 [200]: /assets/img/images/visa.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60453 [200]: /assets/img/images/remita.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60454 [200]: /assets/img/images/master-card.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60460 [200]: /assets/img/images/verve.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60461 [200]: /assets/img/images/indexpartners_11.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60462 [200]: /assets/img/images/bank-branches.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60463 [200]: /assets/img/images/indexpower_03.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60464 [200]: /assets/img/images/paystack.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60465 [200]: /assets/img/images/chams.png
[Thu Aug 22 23:06:10 2019] 127.0.0.1:60468 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:10 2019] 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 [L,R=301]


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

    #Api Redirect
    RewriteCond %REQUEST_URI (.+)/$
    #RewriteRule ^/api$ api.%REQUEST_URI [L,R=301]


    RewriteCond %REQUEST_URI (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %REQUEST_FILENAME !-d
    RewriteCond %REQUEST_FILENAME !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %HTTP:Authorization .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%HTTP:Authorization]

    #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 上提供服务,因为它目前正在重定向

【问题讨论】:

请检查.env文件中的APP_URL应该是这样的:APP_URL=http://localhost @dparoli 我确定了这一点,即使在 config/app.php 中 【参考方案1】:

我尝试了上面推荐的所有方法,但没有任何效果。以下是我解决问题的方法:

我的浏览器正在尝试访问 https://localhost:8000。只需在浏览器地址栏上更改为 http://localhost:800 即可解决问题。花了几天时间修补这个问题,我相信把这个答案留在这里有一天会对某人有所帮助

【讨论】:

【参考方案2】:

我通过将http://localhost:8000 更改为localhost:8000 解决了这个问题

Invalid request (Unsupported SSL request)

【讨论】:

【参考方案3】:
    首先确保 .env 文件中的 APP_URL 类似于 这个:APP_URL=http://localhosthttp://127.0.0.1:8000APP_ENV=production 更改为 APP_ENV=development 然后再次运行 php artisan serve

如果上述方法不起作用

编辑 /app/Providers/AppServiceProvider.php 文件: URL::forceScheme('https');URL::forceScheme('http');

然后再次运行应用程序

【讨论】:

【参考方案4】:

我必须改变

URL::forceScheme('https');

URL::forceScheme('http');

serve --port 我的问题解决了。

php artisan serve --port=8002

【讨论】:

【参考方案5】:

基于@zaghadon 的回复。

最好的解决办法就是使用一个条件:

必须对文件进行更改:app/Providers/AppServiceProvider.php

public function register()

    //check that app is local
    if (!$this->app->isLocal()) 
        //else register your services you require for production
        $this->app['request']->server->set('HTTPS', true);
    

【讨论】:

【参考方案6】:

想分享我的经验,以防它对某人有所帮助。即使我得到了同样的错误。我就是这样解决的。

我在.env 文件中添加了以下内容。

APP_SSL=false

【讨论】:

【参考方案7】:

转到.env 文件, 将APP_ENV=production 更改为APP_ENV=development

然后再次运行php artisan serve

【讨论】:

【参考方案8】:

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

在 app/providers/AppServiceProvider.php 中

寻找 register() 方法,通过检查应用程序是否本地来实现逻辑。 isLocal() 函数检查您的 .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);

【讨论】:

嗨,我遇到了和你一样的问题。我把上面的代码放在 register 方法中,但是你能解释一下这个类 'Barryvdh\Debugbar\ServiceProvider' 是什么吗?我不断收到未定义的错误 @Marko 如果您的项目中没有安装 barryvdh Debugbar,那么您应该在代码中对其进行注释。 对于那些说它没有定义类'Barryvdh\Debugbar\ServiceProvider'的人,你应该检查它是composer.json,所以作曲家更新,或者从:composer require barryvdh/laravel-调试栏 --dev 您好,我也有同样的问题,但是在 laravel 4.2 中,我可以在旧版本中找到这个 AppServiceProvider 吗?? @Tarek Bakri 让我们看看你的设置,然后我知道如何提供帮助。【参考方案9】:

Laravel Framework 7+ 中,您需要编辑 /app/Providers/AppServiceProvider.php 文件:更新

URL::forceScheme('https');

URL::forceScheme('`http`');

然后使用清理缓存

php artisan config:cache

并运行应用程序。

【讨论】:

【参考方案10】:

我通过将 .env 文件中的 APP_URL=http://localhost 更改为 APP_URL=http://127.0.0.1 来解决它

【讨论】:

【参考方案11】:
这就是我修复无效请求(不支持的 SSL 请求)的方法

注意:所有这些更改都必须在您的项目 root 目录中进行

    删除 bootstrap\cache 文件夹内的所有文件(除了 .gitignore 文件,如果你有的话)

    删除vendor文件夹

    在命令行终端中输入composer installcomposer update以安装或更新必要的文件和配置

【讨论】:

【参考方案12】:

我通过禁用缓存解决了这个问题:

第 1 步:

配置\cache.php

'stores' => [
        'none' => [
            'driver' => 'null',
        ],
    ],

第 2 步:

app\Providers\AppServiceProvider.php

在顶部添加

use Illuminate\Cache\NullStore;
use Cache;

在 boot() 方法中添加

Cache::extend('none', function ($app) 
            return Cache::repository(new NullStore);
        );

【讨论】:

以上是关于如何修复无效请求(不支持的 SSL 请求)的主要内容,如果未能解决你的问题,请参考以下文章

如何修复 - 请求的资源不支持 http 方法“POST”

尝试使用 websockets 从 FastAPI 获取实时数据流时如何修复错误(不支持的升级请求。)?

不支持SSL时对HTTPS请求进行规范处理

CUICatalog:无效请求:请求子类型而不指定成语(它来自哪里以及如何修复它?)

如何修复模拟器:qemu-system-x86_64:警告:主机不支持请求的功能:CPUID.80000001H:ECX.abm [位 5]

资源处理程序返回消息:“提供的请求无效:网络负载均衡器侦听器不支持规则