如何解决无效的请求(不支持的SSL请求)

时间:2019-08-22 22:46:16

标签: css laravel http laravel-blade

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

我尝试将HTTPS mod重写规则强制为.htaccess文件上的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上投放,因为它当前正在重定向

10 个答案:

答案 0 :(得分:4)

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

在app / providers / AppServiceProvider.php

寻找register()方法,通过检查tha应用程序是否为本地来实现逻辑。 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);
        }

答案 1 :(得分:2)

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

然后再次运行php artisan serve

答案 2 :(得分:1)

这是我修复无效请求(不支持的SSL请求)的方式

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

  1. 删除 bootstrap \ cache 文件夹中的所有文件( .gitignore 文件除外,也就是说,如果有的话)

  2. 删除供应商文件夹

  3. 在命令行终端中输入composer update,以更新并重新安装必需的文件和配置

答案 3 :(得分:1)

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

步骤1:

config \ 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);
        });

答案 4 :(得分:1)

想分享我的经验,以防万一。甚至我也遇到了同样的错误。我就是这样解决的。

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

<块引用>

APP_SSL=false

答案 5 :(得分:0)

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

答案 6 :(得分:0)

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

URL::forceScheme('https');

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

然后使用清理缓存

php artisan config:cache

并运行应用程序。

答案 7 :(得分:0)

基于@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);
    }
}

答案 8 :(得分:0)

我必须改变

URL::forceScheme('https');

URL::forceScheme('http');

serve --port 并且我的问题已解决。

php artisan serve --port=8002

答案 9 :(得分:0)

  1. 首先确保 .env 文件中的 APP_URL 类似于 这:APP_URL=http://localhosthttp://127.0.0.1:8000
  2. APP_ENV=production更改为APP_ENV=development
  3. 然后再次运行 php artisan serve
<块引用>

如果上述方法不起作用

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

并再次运行应用程序