问题描述
按照标准生产架构部署(宿主机 nginx 终结 HTTPS,反代到 geoflow-web 的 18080 端口)后,
页面能正常打开,但所有表单提交时浏览器都会弹出
"The information you're about to submit is not secure" 警告。
登录页实际渲染结果:
```html
```
浏览器地址栏是 https://,表单 action 却是 http://。
复现条件
- 宿主机 nginx:
listen 443 ssl + proxy_pass http://127.0.0.1:18080,
已正确传递 X-Forwarded-Proto $scheme
- docker-compose 默认配置(geoflow-web 监听 127.0.0.1:18080)
根因分析
问题 1:docker/nginx/local.conf 无条件覆盖 X-Forwarded-Proto
nginx location @geoflow_app { proxy_set_header X-Forwarded-Proto $scheme; # 容器内 $scheme 永远是 http ... }
TLS 在上游代理终结时,容器内 $scheme 恒为 http,把上游传来的
https 覆盖掉了。/reverb/ 的 WebSocket 反代块也有同样问题。
问题 2:bootstrap/app.php 未配置 trustProxies
即使头传对了,Laravel(11)默认不信任任何代理,X-Forwarded-* 头会被忽略。
因此本项目在"TLS 前置代理"这一最常见的生产形态下,生成的 URL 必然降级为 http。
受影响的不止表单 action,还包括:secure cookie 判定、CSRF、
redirect/分页链接、Reverb 的 wss 连接。
修复建议
local.conf:透传上游头,直连时回退本机值
```nginx
map $http_x_forwarded_proto $geoflow_forwarded_proto {
'' $scheme;
default $http_x_forwarded_proto;
}
map $http_x_forwarded_port $geoflow_forwarded_port {
'' $geoflow_host_port;
default $http_x_forwarded_port;
}
location 内改用:
proxy_set_header X-Forwarded-Proto $geoflow_forwarded_proto;
```
bootstrap/app.php:
php $middleware->trustProxies(at: '*'); // 或限定为 docker 网段 172.16.0.0/12
已在本地验证:修复后登录页表单 action 正确生成为 https://,
浏览器警告消失,站点/后台/静态资源均正常。
环境信息
- 部署方式:docker-compose(nginx:1.27-alpine + php artisan serve)
- Laravel 11
问题描述
按照标准生产架构部署(宿主机 nginx 终结 HTTPS,反代到 geoflow-web 的 18080 端口)后,
页面能正常打开,但所有表单提交时浏览器都会弹出
"The information you're about to submit is not secure" 警告。
登录页实际渲染结果:
```html
```浏览器地址栏是 https://,表单 action 却是 http://。
复现条件
listen 443 ssl+proxy_pass http://127.0.0.1:18080,已正确传递
X-Forwarded-Proto $scheme根因分析
问题 1:
docker/nginx/local.conf无条件覆盖X-Forwarded-Proto
nginx location @geoflow_app { proxy_set_header X-Forwarded-Proto $scheme; # 容器内 $scheme 永远是 http ... } TLS 在上游代理终结时,容器内
$scheme恒为http,把上游传来的https覆盖掉了。/reverb/的 WebSocket 反代块也有同样问题。问题 2:
bootstrap/app.php未配置trustProxies即使头传对了,Laravel(11)默认不信任任何代理,
X-Forwarded-*头会被忽略。因此本项目在"TLS 前置代理"这一最常见的生产形态下,生成的 URL 必然降级为 http。
受影响的不止表单 action,还包括:
securecookie 判定、CSRF、redirect/分页链接、Reverb 的 wss 连接。
修复建议
local.conf:透传上游头,直连时回退本机值
```nginx
map $http_x_forwarded_proto $geoflow_forwarded_proto {
'' $scheme;
default $http_x_forwarded_proto;
}
map $http_x_forwarded_port $geoflow_forwarded_port {
'' $geoflow_host_port;
default $http_x_forwarded_port;
}
location 内改用:
proxy_set_header X-Forwarded-Proto $geoflow_forwarded_proto;
```
bootstrap/app.php:
php $middleware->trustProxies(at: '*'); // 或限定为 docker 网段 172.16.0.0/12 已在本地验证:修复后登录页表单 action 正确生成为
https://,浏览器警告消失,站点/后台/静态资源均正常。
环境信息