You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Nginx反向代理部署Laravel 11时Session验证消息不显示问题

Laravel 11验证消息不显示问题(反向代理+LXD容器环境)

我使用nginx作为反向代理,将主机服务器的请求转发至运行Laravel 11应用的LXD容器,整体运行正常,但存在验证消息完全不显示的问题。已排查代码问题:触发验证错误后,本地运行应用能正常输出错误消息,说明问题并非代码导致。

测试情况

  • 本地测试:验证错误正常显示
  • 服务器测试:验证错误完全不显示

已尝试操作

已增大proxy和fastcgi的缓冲区大小,但问题仍存在,推测是整体配置有误。

LXD容器内的Nginx配置

server {
   listen 80;
   server_name lxd-ip;
   root /var/www/public;
   index index.php;
   charset utf-8;

   location / {
       try_files $uri $uri/ /index.php?$query_string;
   }

   location = /favicon.ico {
       access_log off;
       log_not_found off;
   }

   location = /robots.txt {
       access_log off;
       log_not_found off;
   }

   error_page 404 /index.php;

   location ~ \.php$ {
       fastcgi_buffers 20 128k;
       fastcgi_buffer_size 256k;
       fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
       fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
       include fastcgi_params;
   }

   location ~ /\.(?!well-known).* {
       deny all;
   }
}

主机服务器的Nginx配置

server {
   listen 80;
   server_name admin.exemple.com www.exemple.com;
   return 301 https://$server_name$request_uri;
}

server {
   listen 443 ssl;
   ssl_certificate /etc/letsencrypt/live/exemple.com/fullchain.pem;
   ssl_certificate_key /etc/letsencrypt/live/exemple.com/privkey.pem;

   server_name admin.exemple.com;

   location / {
       proxy_pass http://lxd-ip:80;
       proxy_http_version 1.1;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;
       proxy_cookie_path ~^/.*/;
       proxy_cookie_domain admin.exemple.com admin.exemple.com;
       proxy_cache_bypass $http_upgrade;
       proxy_buffer_size 256k;
       proxy_buffers 20 128k;
       proxy_busy_buffers_size 256k;
   }

   location ~ \.php$ {
       fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
       fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
       include fastcgi_params;
       fastcgi_buffers 20 128k;
       fastcgi_buffer_size 256k;
       client_max_body_size 10M;
   }
}

Laravel Session配置

SESSION_DRIVER=cookie
SESSION_LIFETIME=120
SESSION_SECURE_COOKIE=true
SESSION_DOMAIN="admin.exemple.com"
SANCTUM_STATEFUL_DOMAINS="https://admin.exemple.com"
ALLOWED_ORIGINS=https://exemple.com

内容的提问来源于stack exchange,提问作者ya22y

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 02:13:17