Php 拉维尔';auth';中间件设置错误';url.designed';在反向代理后面运行时的会话数据
背景:Php 拉维尔';auth';中间件设置错误';url.designed';在反向代理后面运行时的会话数据,php,laravel,reverse-proxy,Php,Laravel,Reverse Proxy,背景: "HTTP_HOST" => "example.org" "SERVER_NAME" => "example.org" "QUERY_STRING" => "" "REQUEST_URI" => "//foo" "SCRIPT_NAME" => "/index.php" 我正在开发一个Laravel 5.8应用程序,运行在反向代理服务器上的Docker容器中,根据URL子目录将请求转发给应用程序,例如example.org/Laravel/ 一切(路由、H
"HTTP_HOST" => "example.org"
"SERVER_NAME" => "example.org"
"QUERY_STRING" => ""
"REQUEST_URI" => "//foo"
"SCRIPT_NAME" => "/index.php"
我正在开发一个Laravel 5.8应用程序,运行在反向代理服务器上的Docker容器中,根据URL子目录将请求转发给应用程序,例如example.org/Laravel/
一切(路由、HTTPS链接、资产等)都工作正常,除了登录后重定向到预期页面
我已经通过使用完成了路由、资源等的正确URL生成
app('url')->forceRootUrl(config('app.url')); // https://example.org/laravel/
app('url')->forceScheme('https');
我的问题:
"HTTP_HOST" => "example.org"
"SERVER_NAME" => "example.org"
"QUERY_STRING" => ""
"REQUEST_URI" => "//foo"
"SCRIPT_NAME" => "/index.php"
假设我使用auth
中间件定义了一个路由/foo
。当我注销并访问example.org/laravel/foo
时,我被正确地重定向到example.org/laravel/login
,但在登录后,我被重定向到example.org/foo
,它不存在
调查结果:
"HTTP_HOST" => "example.org"
"SERVER_NAME" => "example.org"
"QUERY_STRING" => ""
"REQUEST_URI" => "//foo"
"SCRIPT_NAME" => "/index.php"
注销时访问/foo
auth
中间件抛出一个AuthenticatedException
,该异常在illumb\Routing\Pipeline
中捕获,并传递给illumb\Foundation\Exceptions\Handler::unauthenticated()
(通过Handler::render()
)Handler::unauthenticated()
返回redirect()->guest()
(lighted\Routing\Redirector::guest()
)Redirector::guest()
将url.预定的
会话密钥设置为$this->generator->full()
(照亮\Http\Request::fullUrl()
通过照亮\Routing\UrlGenerator::full()
)Request::fullUrl()
调用Symfony\Component\HttpFoundation\Request::getUri()
(通过$this->url()
)Request::getUri()
从$\u服务器构建URL和请求头数据(见下文),如下所示($qs
:查询字符串):
url.designed
被设置为http://example.org//foo
而不是http://example.org/laravel/foo$\u服务器
数据(摘录):
"HTTP_HOST" => "example.org"
"SERVER_NAME" => "example.org"
"QUERY_STRING" => ""
"REQUEST_URI" => "//foo"
"SCRIPT_NAME" => "/index.php"
确切的Composer软件包版本:
"HTTP_HOST" => "example.org"
"SERVER_NAME" => "example.org"
"QUERY_STRING" => ""
"REQUEST_URI" => "//foo"
"SCRIPT_NAME" => "/index.php"
- laravel/framework:v5.8.3
- symfony/http基金会:v4.2.4
$\u服务器的变量上
将某个域代理到本地ip时,它在HTTP\u POST上设置了错误的值,如下所示:
server {
listen 80;
listen [::]:80;
server_name domain.com;
location / {
proxy_pass http://127.0.0.1:4567;
}
}
我通过在代理上手动设置HTTP\u-HOST
来修复它
在您的情况下,您需要添加以下行:proxy\u set\u header Host example.org/laravel代码>
我的情况和你的略有不同。它将我重定向到http://127.0.0.1:4567
成功登录domain.com
后。因为Laravel的session.url\u previous
是错误的。它来自$\u服务器['HTTP\u主机]
因此,我希望这将帮助你
整个Nginx conf文件:
server {
listen 80;
listen [::]:80;
server_name domain.com;
location / {
#changes happened here
proxy_set_header Host domain.com;
proxy_pass http://127.0.0.1:4567;
}
}
我仔细研究了一下,发现问题出在$\u服务器的变量上
将某个域代理到本地ip时,它在HTTP\u POST上设置了错误的值,如下所示:
server {
listen 80;
listen [::]:80;
server_name domain.com;
location / {
proxy_pass http://127.0.0.1:4567;
}
}
我通过在代理上手动设置HTTP\u-HOST
来修复它
在您的情况下,您需要添加以下行:proxy\u set\u header Host example.org/laravel代码>
我的情况和你的略有不同。它将我重定向到http://127.0.0.1:4567
成功登录domain.com
后。因为Laravel的session.url\u previous
是错误的。它来自$\u服务器['HTTP\u主机]
因此,我希望这将帮助你
整个Nginx conf文件:
server {
listen 80;
listen [::]:80;
server_name domain.com;
location / {
#changes happened here
proxy_set_header Host domain.com;
proxy_pass http://127.0.0.1:4567;
}
}