源请求被阻止

分享于 

1分钟阅读

互联网

  繁體

问题:

我收到这个错误:


Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://stats.g.doubleclick.net



在Nginx配置中,我们有:


add_header X-Frame-Options SAMEORIGIN always;


add_header X-Xss-Protection "1; mode=block" always;


add_header X-Content-Type-Options nosniff always;


add_header Content-Security-Policy "default-src 'self' https: data: 'unsafe-inline' 'unsafe-eval';" always;


add_header Referrer-Policy "no-referrer-when-downgrade";


add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";




答案1:

location (带有proxy_pass指令例如)中,可以动态地生成正确的头:


 if ($http_origin ~ '^(?:https?://)?(?:[a-z0-9_.-]+.)?(?:doubleclick.net|example.com)$')


 {


 more_set_headers 'Access-Control-Allow-Origin: $http_origin';


 more_set_headers 'Access-Control-Allow-Methods: GET, OPTIONS, POST';


 }




Block  Request  Blocked  
相关文章