{"id":57285,"date":"2024-10-10T18:31:13","date_gmt":"2024-10-10T10:31:13","guid":{"rendered":"https:\/\/server.hk\/cnblog\/57285\/"},"modified":"2024-10-10T18:31:13","modified_gmt":"2024-10-10T10:31:13","slug":"nginx-%e6%96%b0%e6%89%8b%e6%95%99%e7%a8%8b%ef%bc%9a%e9%85%8d%e7%bd%ae-mime-%e9%a1%9e%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/57285\/","title":{"rendered":"Nginx \u65b0\u624b\u6559\u7a0b\uff1a\u914d\u7f6e MIME \u985e\u578b"},"content":{"rendered":"<h1 id=\"nginx-%e6%96%b0%e6%89%8b%e6%95%99%e7%a8%8b%ef%bc%9a%e9%85%8d%e7%bd%ae-mime-%e9%a1%9e%e5%9e%8b-WArPYthUmr\">Nginx \u65b0\u624b\u6559\u7a0b\uff1a\u914d\u7f6e MIME \u985e\u578b<\/h1>\n<p>Nginx \u662f\u4e00\u6b3e\u9ad8\u6548\u80fd\u7684\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u975c\u614b\u5167\u5bb9\u7684\u63d0\u4f9b\u548c\u53cd\u5411\u4ee3\u7406\u3002\u7576\u6211\u5011\u5728\u4f7f\u7528 Nginx \u4f3a\u670d\u5668\u6642\uff0c\u6b63\u78ba\u914d\u7f6e MIME \u985e\u578b\u662f\u975e\u5e38\u91cd\u8981\u7684\uff0c\u56e0\u70ba\u5b83\u80fd\u5920\u544a\u8a34\u700f\u89bd\u5668\u5982\u4f55\u8655\u7406\u4e0d\u540c\u985e\u578b\u7684\u6587\u4ef6\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 Nginx \u4e2d\u914d\u7f6e MIME \u985e\u578b\uff0c\u5e6b\u52a9\u65b0\u624b\u7528\u6236\u66f4\u597d\u5730\u7406\u89e3\u9019\u4e00\u904e\u7a0b\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-mime-%e9%a1%9e%e5%9e%8b%ef%bc%9f-WArPYthUmr\">\u4ec0\u9ebc\u662f MIME \u985e\u578b\uff1f<\/h2>\n<p>MIME\uff08Multipurpose Internet Mail Extensions\uff09\u985e\u578b\u662f\u4e00\u7a2e\u6a19\u6e96\uff0c\u7528\u65bc\u63cf\u8ff0\u4e92\u806f\u7db2\u4e0a\u5404\u7a2e\u6587\u4ef6\u7684\u683c\u5f0f\u3002\u6bcf\u7576\u700f\u89bd\u5668\u8acb\u6c42\u4e00\u500b\u6587\u4ef6\u6642\uff0c\u4f3a\u670d\u5668\u6703\u901a\u904e HTTP \u97ff\u61c9\u982d\u4e2d\u7684 Content-Type \u4f86\u544a\u8a34\u700f\u89bd\u5668\u8a72\u6587\u4ef6\u7684 MIME \u985e\u578b\u3002\u9019\u6a23\uff0c\u700f\u89bd\u5668\u5c31\u80fd\u6839\u64da\u6587\u4ef6\u985e\u578b\u9078\u64c7\u5408\u9069\u7684\u65b9\u5f0f\u4f86\u8655\u7406\u5b83\u3002<\/p>\n<h2 id=\"nginx-%e4%b8%ad%e7%9a%84-mime-%e9%a1%9e%e5%9e%8b%e9%85%8d%e7%bd%ae-WArPYthUmr\">Nginx \u4e2d\u7684 MIME \u985e\u578b\u914d\u7f6e<\/h2>\n<p>Nginx \u7684 MIME \u985e\u578b\u914d\u7f6e\u901a\u5e38\u5728\u5176\u4e3b\u914d\u7f6e\u6587\u4ef6\u4e2d\u9032\u884c\uff0c\u8a72\u6587\u4ef6\u901a\u5e38\u4f4d\u65bc \/etc\/nginx\/nginx.conf\u3002Nginx \u6703\u4f7f\u7528\u4e00\u500b\u540d\u70ba mime.types \u7684\u6587\u4ef6\u4f86\u5b9a\u7fa9\u5404\u7a2e\u6587\u4ef6\u64f4\u5c55\u540d\u5c0d\u61c9\u7684 MIME \u985e\u578b\u3002<\/p>\n<h3 id=\"1-%e6%9f%a5%e7%9c%8b%e5%92%8c%e7%b7%a8%e8%bc%af-mime-types-%e6%96%87%e4%bb%b6-WArPYthUmr\">1. \u67e5\u770b\u548c\u7de8\u8f2f mime.types \u6587\u4ef6<\/h3>\n<p>\u9996\u5148\uff0c\u6211\u5011\u53ef\u4ee5\u67e5\u770b Nginx \u7684 mime.types \u6587\u4ef6\uff0c\u901a\u5e38\u4f4d\u65bc \/etc\/nginx\/mime.types\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u67e5\u770b\uff1a<\/p>\n<pre><code>cat \/etc\/nginx\/mime.types<\/code><\/pre>\n<p>\u9019\u500b\u6587\u4ef6\u4e2d\u5217\u51fa\u4e86\u8a31\u591a\u5e38\u898b\u7684\u6587\u4ef6\u64f4\u5c55\u540d\u53ca\u5176\u5c0d\u61c9\u7684 MIME \u985e\u578b\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>text\/html html htm\ntext\/css css\napplication\/javascript js\nimage\/jpeg jpeg jpg\nimage\/png png<\/code><\/pre>\n<h3 id=\"2-%e5%9c%a8-nginx-conf-%e4%b8%ad%e9%85%8d%e7%bd%ae-mime-%e9%a1%9e%e5%9e%8b-WArPYthUmr\">2. \u5728 nginx.conf \u4e2d\u914d\u7f6e MIME \u985e\u578b<\/h3>\n<p>\u5728 Nginx \u7684\u4e3b\u914d\u7f6e\u6587\u4ef6 nginx.conf \u4e2d\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6307\u4ee4\u4f86\u5f15\u5165 mime.types \u6587\u4ef6\uff1a<\/p>\n<pre><code>include       mime.types;<\/code><\/pre>\n<p>\u9019\u6a23\uff0cNginx \u5c31\u6703\u81ea\u52d5\u52a0\u8f09 mime.types \u6587\u4ef6\u4e2d\u7684\u6240\u6709 MIME \u985e\u578b\u914d\u7f6e\u3002\u5982\u679c\u9700\u8981\u6dfb\u52a0\u81ea\u5b9a\u7fa9\u7684 MIME \u985e\u578b\uff0c\u53ef\u4ee5\u76f4\u63a5\u5728 nginx.conf \u4e2d\u9032\u884c\u914d\u7f6e\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>types {\n    application\/vnd.ms-excel xls;\n    application\/pdf pdf;\n}<\/code><\/pre>\n<h3 id=\"3-%e6%b8%ac%e8%a9%a6%e9%85%8d%e7%bd%ae%e4%b8%a6%e9%87%8d%e5%95%9f-nginx-WArPYthUmr\">3. \u6e2c\u8a66\u914d\u7f6e\u4e26\u91cd\u555f Nginx<\/h3>\n<p>\u5b8c\u6210\u914d\u7f6e\u5f8c\uff0c\u5efa\u8b70\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u6e2c\u8a66 Nginx \u914d\u7f6e\u662f\u5426\u6b63\u78ba\uff1a<\/p>\n<pre><code>nginx -t<\/code><\/pre>\n<p>\u5982\u679c\u6c92\u6709\u932f\u8aa4\uff0c\u5247\u53ef\u4ee5\u91cd\u555f Nginx \u4ee5\u4f7f\u914d\u7f6e\u751f\u6548\uff1a<\/p>\n<pre><code>systemctl restart nginx<\/code><\/pre>\n<h2 id=\"%e5%a6%82%e4%bd%95%e6%aa%a2%e6%9f%a5-mime-%e9%a1%9e%e5%9e%8b-WArPYthUmr\">\u5982\u4f55\u6aa2\u67e5 MIME \u985e\u578b<\/h2>\n<p>\u5728\u914d\u7f6e\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528 curl \u547d\u4ee4\u4f86\u6aa2\u67e5\u4f3a\u670d\u5668\u8fd4\u56de\u7684 MIME \u985e\u578b\u3002\u4f8b\u5982\uff0c\u6aa2\u67e5\u4e00\u500b HTML \u6587\u4ef6\u7684 MIME \u985e\u578b\uff1a<\/p>\n<pre><code>curl -I http:\/\/yourdomain.com\/index.html<\/code><\/pre>\n<p>\u5728\u8fd4\u56de\u7684 HTTP \u97ff\u61c9\u4e2d\uff0c\u60a8\u61c9\u8a72\u80fd\u770b\u5230\u985e\u4f3c\u4ee5\u4e0b\u7684\u5167\u5bb9\uff1a<\/p>\n<pre><code>Content-Type: text\/html; charset=UTF-8<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-WArPYthUmr\">\u7e3d\u7d50<\/h2>\n<p>\u6b63\u78ba\u914d\u7f6e MIME \u985e\u578b\u5c0d\u65bc\u78ba\u4fdd\u7db2\u7ad9\u7684\u6b63\u5e38\u904b\u884c\u81f3\u95dc\u91cd\u8981\u3002\u901a\u904e\u672c\u6587\u7684\u4ecb\u7d39\uff0c\u60a8\u61c9\u8a72\u80fd\u5920\u5728 Nginx \u4e2d\u8f15\u9b06\u914d\u7f6e\u548c\u7ba1\u7406 MIME \u985e\u578b\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u7528\u6236\u7684\u9700\u6c42\u3002\u7121\u8ad6\u662f\u975c\u614b\u7db2\u7ad9\u9084\u662f\u52d5\u614b\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a> \u90fd\u80fd\u63d0\u5347\u60a8\u7684\u7db2\u7ad9\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 Nginx \u4e2d\u914d\u7f6e MIME \u985e\u578b\uff0c\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u8207\u517c\u5bb9\u6027\uff0c\u9069\u5408\u65b0\u624b\u7684\u8a73\u7d30\u6559\u7a0b\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-57285","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57285","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=57285"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57285\/revisions"}],"predecessor-version":[{"id":57286,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57285\/revisions\/57286"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=57285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=57285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=57285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}