【问题标题】:Laravel CSRF with SSL load balancing behind nginxLaravel CSRF 与 nginx 后面的 SSL 负载平衡
【发布时间】:2016-02-21 04:42:41
【问题描述】:

我们有一个带有 SSL 终止的 Nginx 负载平衡器。它的后面是两个运行 nginx/laravel 5.1 的 Web 服务器,并且都在 redis 上共享会话。当负载平衡设置为用户返回同一服务器的会话亲和模式时,会话工作正常。如果我们使用轮询,我们将面临 CSRF "Illuminate \ Session \ TokenMismatchException" 并且用户没有获得有效的会话。如何让会话以循环方式工作?

这里是 nginx 上的代理设置。

    proxy_set_header 'Access-Control-Allow-Origin' '*';
    proxy_set_header 'Access-Control-Allow-Credentials' 'true';
    proxy_set_header 'Access-Control-Allow-Headers' 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept';
   proxy_set_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';

在登录刀片上我们有

<div class="signin_form_modal">
    <div class="signin_form">
        <form id="signin_form">
            <div class="modal_header">
                <a href="#" class="modal_back inline" title="close">+</a>
                <h1 class="modal_title">Sign in</h1>
            </div>
        <div class="modal_input_group">
            {!! csrf_field() !!}
            <input type="text" name="email" placeholder="Username or Email" class="email modal-input">
            <input type="password" name="password" placeholder="Password" class="password modal-input">
        </div>
        <div class="modal_footer">
            <!--<a href="#"><i class="fa fa-check"></i> Done</a>-->
            <button class="submit" type="submit"><i class="fa fa-check"></i> Done</button>
        </div>
        </form>
    </div>
</div>

路由定义为

Route::post('/signin', 'Auth\AuthController@signin');

【问题讨论】:

  • 两台服务器是否通过同一个域发送cookie?
  • 嗯,现在在 session.php 配置中,域设置为 null 。我将尝试将其更改为我们的域。感谢您的指点。 @MattStephens
  • 如果您在两个框中将域设置为相同,则会话应该持续存在。

标签: laravel nginx csrf laravel-5.1 laravel-routing


【解决方案1】:

某些提供商的会话存储在本地服务器上。 如果用户因负载均衡而更换服务器,则会话全部丢失。

唯一的解决方案是使用跨服务器共享的会话提供程序。

【讨论】:

    猜你喜欢
    • 2013-03-01
    • 1970-01-01
    • 2022-01-10
    • 2011-04-21
    • 2013-10-12
    • 2020-07-23
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    相关资源
    最近更新 更多