[软件设计/软件工程] 如何修复无效请求(不支持的 SSL 请求)

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

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

这是命令行
  1. C:\Users\topaz\cashurban>php artisan serve
  2. Laravel development server started: <http://127.0.0.1:8000>
  3. [Thu Aug 22 23:06:07 2019] 127.0.0.1:60410 Invalid request (Unsupported SSL request)
  4. [Thu Aug 22 23:06:08 2019] 127.0.0.1:60418 Invalid request (Unsupported SSL request)
  5. [Thu Aug 22 23:06:08 2019] 127.0.0.1:60419 Invalid request (Unsupported SSL request)
  6. [Thu Aug 22 23:06:08 2019] 127.0.0.1:60420 Invalid request (Unsupported SSL request)
  7. [Thu Aug 22 23:06:08 2019] 127.0.0.1:60421 Invalid request (Unsupported SSL request)
  8. [Thu Aug 22 23:06:08 2019] 127.0.0.1:60423 Invalid request (Unsupported SSL request)
  9. [Thu Aug 22 23:06:08 2019] 127.0.0.1:60409 [200]: /assets/img/slider-1.jpg
  10. [Thu Aug 22 23:06:08 2019] 127.0.0.1:60425 Invalid request (Unsupported SSL request)
  11. [Thu Aug 22 23:06:08 2019] 127.0.0.1:60426 Invalid request (Unsupported SSL request)
  12. [Thu Aug 22 23:06:08 2019] 127.0.0.1:60427 Invalid request (Unsupported SSL request)
  13. [Thu Aug 22 23:06:08 2019] 127.0.0.1:60411 [200]: /assets/img/slider-2.jpg
  14. [Thu Aug 22 23:06:08 2019] 127.0.0.1:60435 Invalid request (Unsupported SSL request)
  15. [Thu Aug 22 23:06:08 2019] 127.0.0.1:60437 [200]: /assets/img/slider-3.jpg
  16. [Thu Aug 22 23:06:08 2019] 127.0.0.1:60439 [200]: /assets/img/icon-1-1.png
  17. [Thu Aug 22 23:06:08 2019] 127.0.0.1:60438 [200]: /assets/img/images/index-Recovereddashboard_03.png
  18. [Thu Aug 22 23:06:08 2019] 127.0.0.1:60440 [200]: /assets/img/icon-2-1.png
  19. [Thu Aug 22 23:06:08 2019] 127.0.0.1:60442 [200]: /assets/img/icon-3-1.png
  20. [Thu Aug 22 23:06:08 2019] 127.0.0.1:60447 Invalid request (Unsupported SSL request)
  21. [Thu Aug 22 23:06:09 2019] 127.0.0.1:60448 [200]: /assets/img/tor1.png
  22. [Thu Aug 22 23:06:09 2019] 127.0.0.1:60450 [200]: /assets/img/tor2.png
  23. [Thu Aug 22 23:06:09 2019] 127.0.0.1:60452 [200]: /assets/img/tor3.png
  24. [Thu Aug 22 23:06:09 2019] 127.0.0.1:60455 [200]: /assets/img/images/visa.png
  25. [Thu Aug 22 23:06:09 2019] 127.0.0.1:60453 [200]: /assets/img/images/remita.png
  26. [Thu Aug 22 23:06:09 2019] 127.0.0.1:60454 [200]: /assets/img/images/master-card.png
  27. [Thu Aug 22 23:06:09 2019] 127.0.0.1:60460 [200]: /assets/img/images/verve.png
  28. [Thu Aug 22 23:06:09 2019] 127.0.0.1:60461 [200]: /assets/img/images/indexpartners_11.png
  29. [Thu Aug 22 23:06:09 2019] 127.0.0.1:60462 [200]: /assets/img/images/bank-branches.png
  30. [Thu Aug 22 23:06:09 2019] 127.0.0.1:60463 [200]: /assets/img/images/indexpower_03.png
  31. [Thu Aug 22 23:06:09 2019] 127.0.0.1:60464 [200]: /assets/img/images/paystack.png
  32. [Thu Aug 22 23:06:09 2019] 127.0.0.1:60465 [200]: /assets/img/images/chams.png
  33. [Thu Aug 22 23:06:10 2019] 127.0.0.1:60468 Invalid request (Unsupported SSL request)
  34. [Thu Aug 22 23:06:10 2019] 127.0.0.1:60469 Invalid request (Unsupported SSL request)
复制代码

这是 .htaccess 文件
  1. <IfModule mod_rewrite.c>
  2.     <IfModule mod_negotiation.c>
  3.         Options -MultiViews
  4.     </IfModule>

  5.     RewriteEngine On

  6.     #Force Https

  7.     #RewriteCond %{HTTPS} !=on
  8.     #RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


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

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


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

  16.     # Handle Front Controller...
  17.     RewriteCond %{REQUEST_FILENAME} !-d
  18.     RewriteCond %{REQUEST_FILENAME} !-f
  19.     RewriteRule ^ index.php [L]

  20.     # Handle Authorization Header
  21.     RewriteCond %{HTTP:Authorization} .
  22.     RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

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

  34.     #php_value auto_prepend_file /home/example_project/public_html/error_handler_slack.php
  35.     php_value auto_prepend_file error_handler_slack.php
  36. </IfModule>
复制代码

我希望它提供 http://localhost 而不是 https://localhost 因为它当前正在重定向

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

应用内/providers/AppServiceProvider.php

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






上一篇:Visual Studio Code - 终端 (PowerShell) - 如何复制文本
下一篇:Dynamics CRM - 其他实体的重复工作流

使用道具 举报

Archiver|手机版|小黑屋|吾爱开源 |网站地图

Copyright 2011 - 2012 Lnqq.NET.All Rights Reserved( ICP备案粤ICP备14042591号-1粤ICP14042591号 )

关于本站 - 版权申明 - 侵删联系 - Ln Studio! - 广告联系

本站资源来自互联网,仅供用户测试使用,相关版权归原作者所有

快速回复 返回顶部 返回列表