Laravel 8中的自定义路线仅收听HTTP请求

发布于 2025-02-03 07:25:35 字数 500 浏览 5 评论 0原文

我的应用程序在HTTPS协议上使用端口443的稳定性运行,但是我正在使用AWS EBS,其中始终在HTTP上使用端口80执行健康检查。我创建了用于在所有路线上强制执行HTTPS的中间件,但是当我启用它时,健康检查AWS失败,但该网站正常工作。

HTTPSFORCE中间件处理功能:

public function handle($request, Closure $next)
{

    if (!$request->secure() && app()->environment('production')) {
        return redirect()->secure($request->getRequestUri());
    }
    
    return $next($request);
}

如何创建一个自定义路由,该路由始终使用HTTP协议倾听到端口80,以便AWS的健康检查将在HTTP路由上执行,而我的整个网站在HTTPS工作?

My application works with stability on HTTPS protocol with port 443 but I'm using AWS EBS where health checks are always performed on HTTP with port 80. I've created middleware for enforcing HTTPS on all routes but when I enabled it, the health check fails on AWS but the website works properly.

HTTPsForce middleware handle function:

public function handle($request, Closure $next)
{

    if (!$request->secure() && app()->environment('production')) {
        return redirect()->secure($request->getRequestUri());
    }
    
    return $next($request);
}

How can I create a custom route which listens to port 80 with HTTP protocol always so the health check by AWS would perform on HTTP route while my whole website working in HTTPS?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

刘备忘录 2025-02-10 07:25:35

您可以在特定路由上排除中间件:

Route::get('/', [Controller::class, 'action'])->withoutMiddleware([Middleware::class]);

https://lararavel.com/docs/ 9.x/中间件#排除中间软件

You can exclude middleware on specific routes:

Route::get('/', [Controller::class, 'action'])->withoutMiddleware([Middleware::class]);

https://laravel.com/docs/9.x/middleware#excluding-middleware

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文