×

[已解决] 使用 nginx或cloudflare以https反代http站点, livewire 上传文件发送http协议的请求

2024-01-16 18:12:59 Falcon

兼容http和https的修正方法是

nginx反代的设置(以nginx proxy manager自定义配置为例)

 location /{
        
        proxy_pass $forward_scheme://$server:$port;

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
		# 注意这一行
       proxy_set_header X-Forwarded-Proto https;
	   
    }
   

在blade模板<head>加入:

@if(request()->header('X-Forwarded-Proto') == 'https')
   <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
@endif

相关讨论在https://github.com/livewire/livewire/issues/1216 关于这个指令的说明:修正混合内容  |  Articles  |  web.dev

本文收录于