{"id":49848,"date":"2024-10-08T08:00:13","date_gmt":"2024-10-08T00:00:13","guid":{"rendered":"https:\/\/server.hk\/cnblog\/49848\/"},"modified":"2024-10-08T08:00:13","modified_gmt":"2024-10-08T00:00:13","slug":"nginx-%e6%8a%80%e5%b7%a7%ef%bc%9a%e5%af%a6%e7%8f%be-x-content-type-options-%e9%80%b2%e8%a1%8c-mime-%e9%a1%9e%e5%9e%8b%e5%ae%89%e5%85%a8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/49848\/","title":{"rendered":"Nginx \u6280\u5de7\uff1a\u5be6\u73fe X-Content-Type-Options \u9032\u884c MIME \u985e\u578b\u5b89\u5168"},"content":{"rendered":"<h1 id=\"nginx-%e6%8a%80%e5%b7%a7%ef%bc%9a%e5%af%a6%e7%8f%be-x-content-type-options-%e9%80%b2%e8%a1%8c-mime-%e9%a1%9e%e5%9e%8b%e5%ae%89%e5%85%a8-bcyNtNobeS\">Nginx \u6280\u5de7\uff1a\u5be6\u73fe X-Content-Type-Options \u9032\u884c MIME \u985e\u578b\u5b89\u5168<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u5b89\u5168\u6027\u662f\u6bcf\u500b\u7db2\u7ad9\u7ba1\u7406\u54e1\u5fc5\u9808\u91cd\u8996\u7684\u554f\u984c\u3002\u96a8\u8457\u7db2\u7d61\u653b\u64ca\u624b\u6bb5\u7684\u65e5\u76ca\u589e\u591a\uff0c\u78ba\u4fdd\u7db2\u7ad9\u7684\u5b89\u5168\u6027\u8b8a\u5f97\u5c24\u70ba\u91cd\u8981\u3002X-Content-Type-Options \u662f\u4e00\u500b HTTP \u97ff\u61c9\u6a19\u982d\uff0c\u80fd\u5920\u5e6b\u52a9\u9632\u6b62 MIME \u985e\u578b\u6df7\u6dc6\u653b\u64ca\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5728 Nginx \u4e2d\u5be6\u73fe X-Content-Type-Options\uff0c\u4ee5\u589e\u5f37\u7db2\u7ad9\u7684\u5b89\u5168\u6027\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-x-content-type-options%ef%bc%9f-bcyNtNobeS\">\u4ec0\u9ebc\u662f X-Content-Type-Options\uff1f<\/h2>\n<p>X-Content-Type-Options \u662f\u4e00\u500b HTTP \u97ff\u61c9\u6a19\u982d\uff0c\u4e3b\u8981\u7528\u65bc\u544a\u8a34\u700f\u89bd\u5668\u4e0d\u8981\u6839\u64da\u5167\u5bb9\u7684 MIME \u985e\u578b\u9032\u884c\u731c\u6e2c\u3002\u9019\u610f\u5473\u8457\uff0c\u7576\u4f3a\u670d\u5668\u8fd4\u56de\u4e00\u500b\u6587\u4ef6\u6642\uff0c\u700f\u89bd\u5668\u5c07\u53ea\u6839\u64da\u4f3a\u670d\u5668\u63d0\u4f9b\u7684 MIME \u985e\u578b\u4f86\u8655\u7406\u8a72\u6587\u4ef6\uff0c\u800c\u4e0d\u6703\u5617\u8a66\u63a8\u6e2c\u5176\u985e\u578b\u3002\u9019\u6a23\u53ef\u4ee5\u6709\u6548\u9632\u6b62\u67d0\u4e9b\u985e\u578b\u7684\u653b\u64ca\uff0c\u4f8b\u5982\u8de8\u7ad9\u8173\u672c\uff08XSS\uff09\u653b\u64ca\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81-x-content-type-options%ef%bc%9f-bcyNtNobeS\">\u70ba\u4ec0\u9ebc\u9700\u8981 X-Content-Type-Options\uff1f<\/h2>\n<p>\u8a31\u591a\u653b\u64ca\u8005\u5229\u7528 MIME \u985e\u578b\u6df7\u6dc6\u4f86\u57f7\u884c\u60e1\u610f\u4ee3\u78bc\u3002\u4f8b\u5982\uff0c\u653b\u64ca\u8005\u53ef\u80fd\u6703\u5c07\u4e00\u500b JavaScript \u6587\u4ef6\u7684\u64f4\u5c55\u540d\u66f4\u6539\u70ba .jpg\uff0c\u7136\u5f8c\u5c07\u5176\u4e0a\u50b3\u5230\u4f3a\u670d\u5668\u3002\u5982\u679c\u4f3a\u670d\u5668\u672a\u6b63\u78ba\u8a2d\u7f6e MIME \u985e\u578b\uff0c\u700f\u89bd\u5668\u53ef\u80fd\u6703\u6839\u64da\u6587\u4ef6\u5167\u5bb9\u9032\u884c\u731c\u6e2c\uff0c\u5f9e\u800c\u57f7\u884c\u9019\u500b\u60e1\u610f\u4ee3\u78bc\u3002\u901a\u904e\u8a2d\u7f6e X-Content-Type-Options \u6a19\u982d\u70ba &#8220;nosniff&#8221;\uff0c\u53ef\u4ee5\u9632\u6b62\u9019\u7a2e\u60c5\u6cc1\u7684\u767c\u751f\u3002<\/p>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%9c%a8-nginx-%e4%b8%ad%e8%a8%ad%e7%bd%ae-x-content-type-options-bcyNtNobeS\">\u5982\u4f55\u5728 Nginx \u4e2d\u8a2d\u7f6e X-Content-Type-Options<\/h2>\n<p>\u5728 Nginx \u4e2d\u8a2d\u7f6e X-Content-Type-Options \u6a19\u982d\u975e\u5e38\u7c21\u55ae\u3002\u60a8\u53ea\u9700\u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4e00\u884c\u4ee3\u78bc\u5373\u53ef\u3002\u4ee5\u4e0b\u662f\u5177\u9ad4\u6b65\u9a5f\uff1a<\/p>\n<pre><code>server {\n    listen 80;\n    server_name example.com;\n\n    # \u8a2d\u7f6e X-Content-Type-Options \u6a19\u982d\n    add_header X-Content-Type-Options nosniff;\n\n    location \/ {\n        # \u5176\u4ed6\u914d\u7f6e\n    }\n}<\/code><\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u78bc\u4e2d\uff0c\u60a8\u9700\u8981\u5c07 &#8220;example.com&#8221; \u66ff\u63db\u70ba\u60a8\u7684\u57df\u540d\u3002\u9019\u884c\u4ee3\u78bc\u5c07\u5728\u6240\u6709\u97ff\u61c9\u4e2d\u6dfb\u52a0 X-Content-Type-Options \u6a19\u982d\uff0c\u4e26\u8a2d\u7f6e\u5176\u503c\u70ba &#8220;nosniff&#8221;\u3002<\/p>\n<h2 id=\"%e6%b8%ac%e8%a9%a6-x-content-type-options-%e6%98%af%e5%90%a6%e7%94%9f%e6%95%88-bcyNtNobeS\">\u6e2c\u8a66 X-Content-Type-Options \u662f\u5426\u751f\u6548<\/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-Content-Type-Options \u6a19\u982d\u662f\u5426\u6b63\u78ba\u8a2d\u7f6e\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 curl \u547d\u4ee4\u6aa2\u67e5\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>curl -I http:\/\/example.com<\/code><\/pre>\n<p>\u5982\u679c\u8a2d\u7f6e\u6b63\u78ba\uff0c\u60a8\u61c9\u8a72\u80fd\u5920\u5728\u97ff\u61c9\u4e2d\u770b\u5230\u985e\u4f3c\u4ee5\u4e0b\u7684\u5167\u5bb9\uff1a<\/p>\n<pre><code>X-Content-Type-Options: nosniff<\/code><\/pre>\n<h2 id=\"%e7%b5%90%e8%ab%96-bcyNtNobeS\">\u7d50\u8ad6<\/h2>\n<p>\u901a\u904e\u5728 Nginx \u4e2d\u8a2d\u7f6e X-Content-Type-Options \u6a19\u982d\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u589e\u5f37\u7db2\u7ad9\u7684\u5b89\u5168\u6027\uff0c\u9632\u6b62 MIME \u985e\u578b\u6df7\u6dc6\u653b\u64ca\u3002\u9019\u662f\u4e00\u500b\u7c21\u55ae\u800c\u6709\u6548\u7684\u63aa\u65bd\uff0c\u80fd\u5920\u70ba\u60a8\u7684\u7db2\u7ad9\u63d0\u4f9b\u984d\u5916\u7684\u4fdd\u8b77\u3002\u96a8\u8457\u7db2\u7d61\u5b89\u5168\u5a01\u8105\u7684\u589e\u52a0\uff0c\u7db2\u7ad9\u7ba1\u7406\u54e1\u61c9\u8a72\u91cd\u8996\u9019\u4e9b\u5b89\u5168\u63aa\u65bd\uff0c\u4ee5\u78ba\u4fdd\u7528\u6236\u7684\u6578\u64da\u5b89\u5168\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\u7db2\u7ad9\u5b89\u5168\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u5728 Nginx \u4e2d\u5be6\u73fe X-Content-Type-Options \u6a19\u982d\uff0c\u589e\u5f37 MIME \u985e\u578b\u5b89\u5168\uff0c\u4fdd\u8b77\u7db2\u7ad9\u514d\u53d7\u5167\u5bb9\u985e\u578b\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-49848","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49848","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=49848"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49848\/revisions"}],"predecessor-version":[{"id":49849,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49848\/revisions\/49849"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=49848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=49848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=49848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}