{"id":36341,"date":"2024-10-01T07:51:40","date_gmt":"2024-09-30T23:51:40","guid":{"rendered":"https:\/\/server.hk\/cnblog\/36341\/"},"modified":"2024-10-01T07:51:40","modified_gmt":"2024-09-30T23:51:40","slug":"apache%e5%ae%89%e5%85%a8%e7%ad%96%e7%95%a5%ef%bc%9a%e4%bd%bf%e7%94%a8x-frame-options%e9%98%b2%e6%ad%a2%e9%bb%9e%e6%93%8a%e5%8a%ab%e6%8c%81","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/36341\/","title":{"rendered":"Apache\u5b89\u5168\u7b56\u7565\uff1a\u4f7f\u7528X-Frame-Options\u9632\u6b62\u9ede\u64ca\u52ab\u6301"},"content":{"rendered":"<h1 id=\"apache%e5%ae%89%e5%85%a8%e7%ad%96%e7%95%a5%ef%bc%9a%e4%bd%bf%e7%94%a8x-frame-options%e9%98%b2%e6%ad%a2%e9%bb%9e%e6%93%8a%e5%8a%ab%e6%8c%81-pkhFxrAxUn\">Apache\u5b89\u5168\u7b56\u7565\uff1a\u4f7f\u7528X-Frame-Options\u9632\u6b62\u9ede\u64ca\u52ab\u6301<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u7db2\u7ad9\u5b89\u5168\u6027\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\u3002\u96a8\u8457\u7db2\u7d61\u653b\u64ca\u624b\u6bb5\u7684\u591a\u6a23\u5316\uff0c\u7db2\u7ad9\u7ba1\u7406\u8005\u5fc5\u9808\u63a1\u53d6\u6709\u6548\u7684\u63aa\u65bd\u4f86\u4fdd\u8b77\u7528\u6236\u7684\u5b89\u5168\u3002\u5176\u4e2d\uff0c\u9ede\u64ca\u52ab\u6301\uff08Clickjacking\uff09\u662f\u4e00\u7a2e\u5e38\u898b\u7684\u653b\u64ca\u65b9\u5f0f\uff0c\u653b\u64ca\u8005\u901a\u904e\u5c07\u53d7\u5bb3\u8005\u7684\u700f\u89bd\u5668\u754c\u9762\u8986\u84cb\u5728\u4e00\u500b\u96b1\u85cf\u7684iframe\u4e2d\uff0c\u8a98\u4f7f\u7528\u6236\u57f7\u884c\u4e0d\u77e5\u60c5\u7684\u64cd\u4f5c\u3002\u70ba\u4e86\u9632\u6b62\u9019\u7a2e\u653b\u64ca\uff0cApache\u4f3a\u670d\u5668\u53ef\u4ee5\u4f7f\u7528HTTP\u6a19\u982d\u4e2d\u7684X-Frame-Options\u4f86\u589e\u5f37\u5b89\u5168\u6027\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afx-frame-options%ef%bc%9f-pkhFxrAxUn\">\u4ec0\u9ebc\u662fX-Frame-Options\uff1f<\/h2>\n<p>X-Frame-Options\u662f\u4e00\u500bHTTP\u97ff\u61c9\u6a19\u982d\uff0c\u7528\u65bc\u544a\u8a34\u700f\u89bd\u5668\u662f\u5426\u5141\u8a31\u7576\u524d\u9801\u9762\u88ab\u5d4c\u5165\u5230iframe\u4e2d\u3002\u9019\u500b\u6a19\u982d\u53ef\u4ee5\u6709\u6548\u5730\u9632\u6b62\u9ede\u64ca\u52ab\u6301\u653b\u64ca\u3002X-Frame-Options\u6709\u4e09\u500b\u4e3b\u8981\u7684\u53d6\u503c\uff1a<\/p>\n<ul>\n<li><strong>DENY<\/strong>\uff1a\u5b8c\u5168\u7981\u6b62\u8a72\u9801\u9762\u88ab\u4efb\u4f55iframe\u5d4c\u5165\u3002<\/li>\n<li><strong>SAMEORIGIN<\/strong>\uff1a\u50c5\u5141\u8a31\u540c\u6e90\u7684\u9801\u9762\u5d4c\u5165\u8a72\u9801\u9762\u3002<\/li>\n<li><strong>ALLOW-FROM uri<\/strong>\uff1a\u50c5\u5141\u8a31\u6307\u5b9a\u7684URI\u5d4c\u5165\u8a72\u9801\u9762\uff08\u6ce8\u610f\uff1a\u6b64\u9078\u9805\u5728\u67d0\u4e9b\u700f\u89bd\u5668\u4e2d\u4e0d\u88ab\u652f\u6301\uff09\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%9c%a8apache%e4%b8%ad%e9%85%8d%e7%bd%aex-frame-options-pkhFxrAxUn\">\u5982\u4f55\u5728Apache\u4e2d\u914d\u7f6eX-Frame-Options<\/h2>\n<p>\u5728Apache\u4f3a\u670d\u5668\u4e2d\u914d\u7f6eX-Frame-Options\u975e\u5e38\u7c21\u55ae\u3002\u60a8\u53ef\u4ee5\u901a\u904e\u4fee\u6539Apache\u7684\u914d\u7f6e\u6587\u4ef6\u6216\u4f7f\u7528.htaccess\u6587\u4ef6\u4f86\u5be6\u73fe\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u5728\u9019\u5169\u7a2e\u60c5\u6cc1\u4e0b\u9032\u884c\u914d\u7f6e\u7684\u793a\u4f8b\uff1a<\/p>\n<h3 id=\"1-%e4%bf%ae%e6%94%b9apache%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6-pkhFxrAxUn\">1. \u4fee\u6539Apache\u914d\u7f6e\u6587\u4ef6<\/h3>\n<pre><code>\n# \u6253\u958bApache\u914d\u7f6e\u6587\u4ef6\nsudo nano \/etc\/httpd\/conf\/httpd.conf\n\n# \u5728\u9069\u7576\u7684\u4f4d\u7f6e\u6dfb\u52a0\u4ee5\u4e0b\u884c\nHeader always set X-Frame-Options \"DENY\"\n<\/code><\/pre>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8-htaccess%e6%96%87%e4%bb%b6-pkhFxrAxUn\">2. \u4f7f\u7528.htaccess\u6587\u4ef6<\/h3>\n<pre><code>\n# \u6253\u958b\u6216\u5275\u5efa.htaccess\u6587\u4ef6\nnano \/path\/to\/your\/document\/root\/.htaccess\n\n# \u6dfb\u52a0\u4ee5\u4e0b\u884c\nHeader always set X-Frame-Options \"DENY\"\n<\/code><\/pre>\n<p>\u5b8c\u6210\u914d\u7f6e\u5f8c\uff0c\u8acb\u91cd\u555fApache\u4f3a\u670d\u5668\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\uff1a<\/p>\n<pre><code>\nsudo systemctl restart httpd\n<\/code><\/pre>\n<h2 id=\"%e6%b8%ac%e8%a9%a6x-frame-options%e9%85%8d%e7%bd%ae-pkhFxrAxUn\">\u6e2c\u8a66X-Frame-Options\u914d\u7f6e<\/h2>\n<p>\u914d\u7f6e\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u700f\u89bd\u5668\u7684\u958b\u767c\u8005\u5de5\u5177\u4f86\u6aa2\u67e5X-Frame-Options\u6a19\u982d\u662f\u5426\u6b63\u78ba\u8a2d\u7f6e\u3002\u6253\u958b\u958b\u767c\u8005\u5de5\u5177\uff0c\u5207\u63db\u5230\u201c\u7db2\u7d61\u201d\u9078\u9805\u5361\uff0c\u7136\u5f8c\u91cd\u65b0\u52a0\u8f09\u9801\u9762\u3002\u67e5\u770b\u97ff\u61c9\u6a19\u982d\uff0c\u78ba\u8a8dX-Frame-Options\u7684\u503c\u662f\u5426\u5982\u60a8\u6240\u8a2d\u7f6e\u7684\u90a3\u6a23\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-pkhFxrAxUn\">\u7d50\u8ad6<\/h2>\n<p>\u9ede\u64ca\u52ab\u6301\u662f\u4e00\u7a2e\u6f5b\u5728\u7684\u5b89\u5168\u5a01\u8105\uff0c\u800cX-Frame-Options\u662f\u4e00\u500b\u7c21\u55ae\u800c\u6709\u6548\u7684\u9632\u8b77\u63aa\u65bd\u3002\u901a\u904e\u5728Apache\u4f3a\u670d\u5668\u4e2d\u6b63\u78ba\u914d\u7f6eX-Frame-Options\u6a19\u982d\uff0c\u7db2\u7ad9\u7ba1\u7406\u8005\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u7db2\u7ad9\u7684\u5b89\u5168\u6027\uff0c\u4fdd\u8b77\u7528\u6236\u514d\u53d7\u6b64\u985e\u653b\u64ca\u7684\u5f71\u97ff\u3002<\/p>\n<p>\u5c0d\u65bc\u5c0b\u6c42\u7a69\u5b9a\u548c\u5b89\u5168\u7684\u865b\u64ec\u79c1\u4eba\u4f3a\u670d\u5668\uff08<a href=\"https:\/\/server.hk\">VPS<\/a>\uff09\u89e3\u6c7a\u65b9\u6848\u7684\u7528\u6236\uff0c\u9078\u64c7\u5408\u9069\u7684\u670d\u52d9\u63d0\u4f9b\u5546\u81f3\u95dc\u91cd\u8981\u3002\u4e86\u89e3\u66f4\u591a\u6709\u95dc<em>\u9999\u6e2f\u4f3a\u670d\u5668<\/em>\u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u4f7f\u7528X-Frame-Options\u5728Apache\u4e2d\u5be6\u65bd\u5b89\u5168\u7b56\u7565\uff0c\u6709\u6548\u9632\u6b62\u9ede\u64ca\u52ab\u6301\u653b\u64ca\uff0c\u4fdd\u8b77\u7db2\u7ad9\u5b89\u5168\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-36341","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/36341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=36341"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/36341\/revisions"}],"predecessor-version":[{"id":36342,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/36341\/revisions\/36342"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=36341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=36341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=36341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}