我在一个主机中有两个Laravel 5.2应用程序,一个用于生产,另一个用于登台。两者都有自己的数据库。问题是,每当我使用一个应用程序登录时,另一个应用程序将无法登录。有人知道如何处理它吗?
我找到了一个答案,但它不起作用 2 个 Laravel 应用程序,只有一个可以登录
这是我对会话的配置.php
'driver' => env('SESSION_DRIVER', 'file'),
'files' => storage_path('framework/sessions'),
'cookie' => env('SESSION_NAME', 'laravel_local'),
'path' => '/',
'domain' => null,
用于引用您的会话的 Cookie 似乎正在两个应用程序之间共享。
确保两个应用在config/session.php
配置文件中的cookie
配置具有不同的值。
'cookie' => 'laravel_session',
或者,如果您使用 .env 文件(我注意到您是)来设置 cookie 名称,请确保在每个应用程序的 .env 文件中更改相应的变量。
请务必在进行更改后清除浏览器的 Cookie。
如果可能的话,为暂存应用程序创建一个子域(如 staging.yoursite.com
)将是一个理想的解决方案,因为它可以防止在两个应用程序之间共享 cookie。
假设你有这个应用树:
/path/to/web/root
|_app1
| |_all
| |_laravel
| |_folders
| |_and
| |_public
|
|_app2
|_all
|_laravel
|_folders
|_and
|_public
如果您可以管理DNS记录,我建议创建两个虚拟服务器...
例如,第一个app1.application.com
指向/path/to/web/root/app1/public
例如,seccond app2.application.com
指向/path/to/web/root/app2/public
在您的情况下,您可能想使用类似
prod.application.com
和staging.application.com
配置虚拟服务器
如果您使用的是 apache,您的虚拟服务器配置文件可能如下所示:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName app1.application.com
ServerAdmin webmaster@localhost
DocumentRoot /path/to/web/root/app1/public
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
<Directory /path/to/web/root/app1/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
如果您使用的是 Nginx,您的虚拟服务器配置文件可能如下所示:
server {
listen 80;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /path/to/web/root/app1/public;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name sigesi.tk www.sigesi.tk;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$query_string;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ '.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+'.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
配置文件应保存在 Web 服务器配置目录(/etc/apache2
或 /etc/nginx
),sites-aviable
目录中。
然后你必须运行sudo a2ensite <fileName>
(对于Apache)或sudo ln -s /etc/nginx/sites-aviable/<fileName> /etc/nginx/sites-enabled/<fileName>
(对于nginx)...
最后,您必须重新启动网络服务器...
希望这有帮助。
问候。