三種指令值:
DENY:完全禁止嵌入SAMEORIGIN:僅允許同源域名嵌入ALLOW-FROM uri:允許指定來源(現代瀏覽器已棄用,推薦 CSP frame-ancestors)<?php
header('X-Frame-Options: DENY'); // 或 SAMEORIGIN
?>
# 全站
add_header X-Frame-Options SAMEORIGIN;
# 特定 location
location / {
add_header X-Frame-Options SAMEORIGIN;
}
Header always append X-Frame-Options SAMEORIGIN
X-Frame-Options 逐漸被 CSP: frame-ancestors 取代,支持更靈活的策略:
# PHP
header("Content-Security-Policy: frame-ancestors 'self' https://trusted.com;");
# Nginx
add_header Content-Security-Policy "frame-ancestors 'self' https://trusted.com;";
# Apache
Header always set Content-Security-Policy "frame-ancestors 'self' https://trusted.com;"
Refused to display in a frame because X-Frame-OptionsCSP frame-ancestorsX-Frame-Options: SAMEORIGINALLOW-FROM(主流瀏覽器已不支持)