首页 > 解决方案 > Laravel:部署到服务器时会话不会保持活动状态

问题描述

每次我对用户进行身份验证时,只要我不离开页面或关闭选项卡,会话就会保持活动状态,但是,当我再次访问页面时,会话将关闭,我必须再次进行身份验证,仅此而已当我部署服务器时发生,因为它在本地正常工作,我已经查看了所有相关文件,这是我的 session.php 文件

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Session Driver
    |--------------------------------------------------------------------------
    |
    | This option controls the default session "driver" that will be used on
    | requests. By default, we will use the lightweight native driver but
    | you may specify any of the other wonderful drivers provided here.
    |
    | Supported: "file", "cookie", "database", "apc",
    |            "memcached", "redis", "array"
    |
    */

    'driver' => env('SESSION_DRIVER', 'file'),

    /*
    |--------------------------------------------------------------------------
    | Session Lifetime
    |--------------------------------------------------------------------------
    |
    | Here you may specify the number of minutes that you wish the session
    | to be allowed to remain idle before it expires. If you want them
    | to immediately expire on the browser closing, set that option.
    |
    */

    'lifetime' => env('SESSION_LIFETIME', 120),

    'expire_on_close' => false,

这是我的 .env 文件

BROADCAST_DRIVER=log
CACHE_DRIVER=array
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync

服务器上我项目中的所有文件夹都有 777 权限,会发生什么?

标签: linuxlaravelauthenticationsessionsession-state

解决方案


使用数据库会话驱动程序将解决您的问题并提高代码质量。查看此文档部分,了解如何配置它。


推荐阅读