{"id":49994,"date":"2024-10-08T09:11:15","date_gmt":"2024-10-08T01:11:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/49994\/"},"modified":"2024-10-08T09:11:15","modified_gmt":"2024-10-08T01:11:15","slug":"nginx-%e6%8a%80%e5%b7%a7%ef%bc%9a%e5%af%a6%e7%8f%be%e5%83%8f-x-frame-options-%e9%80%99%e6%a8%a3%e7%9a%84%e5%ae%89%e5%85%a8%e9%a0%ad","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/49994\/","title":{"rendered":"Nginx \u6280\u5de7\uff1a\u5be6\u73fe\u50cf X-Frame-Options \u9019\u6a23\u7684\u5b89\u5168\u982d"},"content":{"rendered":"<h1 id=\"nginx-%e6%8a%80%e5%b7%a7%ef%bc%9a%e5%af%a6%e7%8f%be%e5%83%8f-x-frame-options-%e9%80%99%e6%a8%a3%e7%9a%84%e5%ae%89%e5%85%a8%e9%a0%ad-JhbAfwBtgE\">Nginx \u6280\u5de7\uff1a\u5be6\u73fe\u50cf X-Frame-Options \u9019\u6a23\u7684\u5b89\u5168\u982d<\/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\u9700\u8981\u63a1\u53d6\u5404\u7a2e\u63aa\u65bd\u4f86\u4fdd\u8b77\u5176\u7db2\u7ad9\u53ca\u7528\u6236\u7684\u6578\u64da\u3002Nginx \u4f5c\u70ba\u4e00\u500b\u9ad8\u6548\u7684\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u4e0d\u50c5\u80fd\u5920\u63d0\u4f9b\u5353\u8d8a\u7684\u6027\u80fd\uff0c\u9084\u80fd\u901a\u904e\u914d\u7f6e\u5b89\u5168\u982d\u4f86\u589e\u5f37\u7db2\u7ad9\u7684\u5b89\u5168\u6027\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5728 Nginx \u4e2d\u5be6\u73fe X-Frame-Options \u5b89\u5168\u982d\uff0c\u4e26\u63d0\u4f9b\u76f8\u95dc\u7684\u914d\u7f6e\u793a\u4f8b\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-x-frame-options%ef%bc%9f-JhbAfwBtgE\">\u4ec0\u9ebc\u662f X-Frame-Options\uff1f<\/h2>\n<p>X-Frame-Options \u662f\u4e00\u500b HTTP \u97ff\u61c9\u982d\uff0c\u7528\u65bc\u9632\u6b62\u7db2\u7ad9\u88ab\u5d4c\u5165\u5230\u5176\u4ed6\u7db2\u7ad9\u7684 iframe \u4e2d\u3002\u9019\u7a2e\u653b\u64ca\u65b9\u5f0f\u7a31\u70ba\u300c\u9ede\u64ca\u52ab\u6301\u300d\uff0c\u653b\u64ca\u8005\u53ef\u4ee5\u901a\u904e\u5c07\u53d7\u5bb3\u8005\u7684\u7db2\u7ad9\u5d4c\u5165\u5230\u81ea\u5df1\u7684\u9801\u9762\u4e2d\uff0c\u8a98\u4f7f\u7528\u6236\u9032\u884c\u4e0d\u5b89\u5168\u7684\u64cd\u4f5c\u3002\u901a\u904e\u8a2d\u7f6e X-Frame-Options\uff0c\u7db2\u7ad9\u7ba1\u7406\u8005\u53ef\u4ee5\u6709\u6548\u5730\u9632\u6b62\u9019\u7a2e\u653b\u64ca\u3002<\/p>\n<h2 id=\"x-frame-options-%e7%9a%84%e5%80%bc-JhbAfwBtgE\">X-Frame-Options \u7684\u503c<\/h2>\n<p>X-Frame-Options \u6709\u4e09\u500b\u4e3b\u8981\u7684\u503c\uff1a<\/p>\n<ul>\n<li><code>DENY<\/code>\uff1a\u5b8c\u5168\u7981\u6b62\u4efb\u4f55\u7db2\u7ad9\u5c07\u8a72\u9801\u9762\u5d4c\u5165\u5230 iframe \u4e2d\u3002<\/li>\n<li><code>SAMEORIGIN<\/code>\uff1a\u50c5\u5141\u8a31\u540c\u6e90\u7684\u7db2\u7ad9\u5c07\u8a72\u9801\u9762\u5d4c\u5165\u5230 iframe \u4e2d\u3002<\/li>\n<li><code>ALLOW-FROM uri<\/code>\uff1a\u50c5\u5141\u8a31\u6307\u5b9a\u7684 URI \u5c07\u8a72\u9801\u9762\u5d4c\u5165\u5230 iframe \u4e2d\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%a8-nginx-%e4%b8%ad%e8%a8%ad%e7%bd%ae-x-frame-options-JhbAfwBtgE\">\u5982\u4f55\u5728 Nginx \u4e2d\u8a2d\u7f6e X-Frame-Options<\/h2>\n<p>\u5728 Nginx \u4e2d\u8a2d\u7f6e X-Frame-Options \u975e\u5e38\u7c21\u55ae\u3002\u60a8\u53ea\u9700\u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u76f8\u61c9\u7684\u6307\u4ee4\u5373\u53ef\u3002\u4ee5\u4e0b\u662f\u8a2d\u7f6e X-Frame-Options \u7684\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-1%ef%bc%9a%e7%b7%a8%e8%bc%af-nginx-%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6-JhbAfwBtgE\">\u6b65\u9a5f 1\uff1a\u7de8\u8f2f Nginx \u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u627e\u5230\u4e26\u7de8\u8f2f Nginx \u7684\u914d\u7f6e\u6587\u4ef6\u3002\u901a\u5e38\uff0c\u8a72\u6587\u4ef6\u4f4d\u65bc <code>\/etc\/nginx\/nginx.conf<\/code> \u6216\u8005 <code>\/etc\/nginx\/sites-available\/default<\/code>\u3002\u4f7f\u7528\u60a8\u559c\u6b61\u7684\u6587\u672c\u7de8\u8f2f\u5668\u6253\u958b\u8a72\u6587\u4ef6\u3002<\/p>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-2%ef%bc%9a%e6%b7%bb%e5%8a%a0-x-frame-options-%e6%8c%87%e4%bb%a4-JhbAfwBtgE\">\u6b65\u9a5f 2\uff1a\u6dfb\u52a0 X-Frame-Options \u6307\u4ee4<\/h3>\n<p>\u5728 server \u5340\u584a\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u884c\u4f86\u8a2d\u7f6e X-Frame-Options\uff1a<\/p>\n<pre><code>add_header X-Frame-Options \"DENY\";<\/code><\/pre>\n<p>\u9019\u6a23\u7684\u914d\u7f6e\u5c07\u5b8c\u5168\u7981\u6b62\u4efb\u4f55\u7db2\u7ad9\u5c07\u8a72\u9801\u9762\u5d4c\u5165\u5230 iframe \u4e2d\u3002\u5982\u679c\u60a8\u5e0c\u671b\u5141\u8a31\u540c\u6e90\u7684\u7db2\u7ad9\u5d4c\u5165\uff0c\u53ef\u4ee5\u5c07\u5176\u66f4\u6539\u70ba\uff1a<\/p>\n<pre><code>add_header X-Frame-Options \"SAMEORIGIN\";<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-3%ef%bc%9a%e9%87%8d%e5%95%9f-nginx-JhbAfwBtgE\">\u6b65\u9a5f 3\uff1a\u91cd\u555f Nginx<\/h3>\n<p>\u5b8c\u6210\u914d\u7f6e\u5f8c\uff0c\u60a8\u9700\u8981\u91cd\u555f Nginx \u4ee5\u4f7f\u66f4\u6539\u751f\u6548\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u91cd\u555f Nginx\uff1a<\/p>\n<pre><code>sudo systemctl restart nginx<\/code><\/pre>\n<h2 id=\"%e6%b8%ac%e8%a9%a6-x-frame-options-%e8%a8%ad%e7%bd%ae-JhbAfwBtgE\">\u6e2c\u8a66 X-Frame-Options \u8a2d\u7f6e<\/h2>\n<p>\u8a2d\u7f6e\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u700f\u89bd\u5668\u7684\u958b\u767c\u8005\u5de5\u5177\u6216\u547d\u4ee4\u884c\u5de5\u5177\u4f86\u6aa2\u67e5 X-Frame-Options \u662f\u5426\u6b63\u78ba\u8a2d\u7f6e\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u53ef\u4ee5\u67e5\u770b HTTP \u97ff\u61c9\u982d\uff1a<\/p>\n<pre><code>curl -I http:\/\/yourdomain.com<\/code><\/pre>\n<p>\u5982\u679c\u8a2d\u7f6e\u6b63\u78ba\uff0c\u60a8\u61c9\u8a72\u80fd\u5920\u5728\u97ff\u61c9\u982d\u4e2d\u770b\u5230 X-Frame-Options \u7684\u503c\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-JhbAfwBtgE\">\u7d50\u8ad6<\/h2>\n<p>\u901a\u904e\u5728 Nginx \u4e2d\u8a2d\u7f6e X-Frame-Options\uff0c\u7db2\u7ad9\u7ba1\u7406\u8005\u53ef\u4ee5\u6709\u6548\u5730\u9632\u6b62\u9ede\u64ca\u52ab\u6301\u653b\u64ca\uff0c\u5f9e\u800c\u589e\u5f37\u7db2\u7ad9\u7684\u5b89\u5168\u6027\u3002\u9019\u662f\u4e00\u500b\u7c21\u55ae\u800c\u6709\u6548\u7684\u63aa\u65bd\uff0c\u5efa\u8b70\u6240\u6709\u7db2\u7ad9\u7ba1\u7406\u8005\u90fd\u61c9\u8a72\u5be6\u65bd\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u53ef\u9760\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u8f15\u9b06\u7ba1\u7406\u60a8\u7684\u7db2\u7ad9\u548c\u61c9\u7528\u7a0b\u5e8f\u3002\u7121\u8ad6\u662f\u9700\u8981\u9ad8\u6027\u80fd\u7684 <a href=\"https:\/\/server.hk\">\u4e91\u4f3a\u670d\u5668<\/a> \u9084\u662f\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a>\uff0c\u6211\u5011\u90fd\u80fd\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 Nginx \u4e2d\u8a2d\u7f6e X-Frame-Options \u5b89\u5168\u982d\uff0c\u589e\u5f37\u7db2\u7ad9\u9632\u8b77\uff0c\u9632\u6b62 clickjacking \u653b\u64ca\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-49994","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49994","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=49994"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49994\/revisions"}],"predecessor-version":[{"id":49995,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49994\/revisions\/49995"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=49994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=49994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=49994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}