{"id":41448,"date":"2024-12-01T08:18:23","date_gmt":"2024-12-01T00:18:23","guid":{"rendered":"https:\/\/fwq.ai\/blog\/41448\/"},"modified":"2024-12-01T08:18:23","modified_gmt":"2024-12-01T00:18:23","slug":"%e5%a6%82%e4%bd%95%e8%b0%83%e7%94%a8%e9%9d%99%e6%80%81html%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/41448\/","title":{"rendered":"\u5982\u4f55\u8c03\u7528\u9759\u6001HTML\u6587\u4ef6"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>\u5982\u4f55\u8c03\u7528\u9759\u6001HTML\u6587\u4ef6<\/span><\/p>\n<h1>\u5982\u4f55\u8c03\u7528\u9759\u6001HTML\u6587\u4ef6<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-20 10:39:38<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>IT\u884c\u4e1a\u76f8\u5bf9\u4e8e\u4e00\u822c\u4f20\u7edf\u884c\u4e1a\uff0c\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u66f4\u5feb\uff0c\u4e00\u65e6\u505c\u6b62\u4e86\u5b66\u4e60\uff0c\u5f88\u5feb\u5c31\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u8e0f\u8e0f\u5b9e\u5b9e\u7684\u4e0d\u65ad\u5b66\u4e60\uff0c\u7cbe\u8fdb\u81ea\u5df1\u7684\u6280\u672f\uff0c\u5c24\u5176\u662f\u521d\u5b66\u8005\u3002\u4eca\u5929\u7c73\u4e91\u7ed9\u5927\u5bb6\u6574\u7406\u4e86\u300a\u5982\u4f55\u8c03\u7528\u9759\u6001HTML\u6587\u4ef6\u300b\uff0c\u804a\u804a\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b <code>index.html<\/code> \u6587\u4ef6\u7684\u9759\u6001\u6587\u4ef6\u5939\uff0c\u5e76\u5728\u6211\u7684 go \u6587\u4ef6\u4e2d\u5199\u9053\uff1a<\/p>\n<pre>package main\n\nimport (\n    \"net\/http\"\n)\n\nfunc main() {\n    http.handle(\"\/\", http.fileserver(http.dir(\".\/static\")))\n\n    http.listenandserve(\":8482\", nil)\n}\n<\/pre>\n<p>\u5728\u63a2\u7d22 <code>http:\/\/localhost:8482\/<\/code> \u65f6\u6548\u679c\u5f88\u597d<\/p>\n<p>\u6211\u5c1d\u8bd5\u5c06\u4ee3\u7801\u7f16\u5199\u4e3a\uff1a<\/p>\n<pre>http.Handle(\"\/static\", http.FileServer(http.Dir(\".\/static\")))\n<\/pre>\n<p>\u4f46\u662f\u5728\u63a2\u7d22 <code>http:\/\/localhost:8482\/static<\/code> \u65f6\u5931\u8d25\u5e76\u51fa\u73b0 404 \u9519\u8bef<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p><code>http.handle(\"\/static\", http.fileserver(http.dir(\".\/static\")))<\/code> \u53ea\u662f\u610f\u5473\u7740\uff0c\u201c\u6bcf\u5f53\u6709\u4eba\u8fde\u63a5\u5230 <code>...\/static<\/code> \u65f6\uff0c\u5c06\u6574\u4e2a\u8bf7\u6c42\u91cd\u65b0\u8def\u7531\u5230\u6587\u4ef6\u670d\u52a1\u5668\u6839\u76ee\u5f55\u4e3a .\/static&#8221;\u3002<\/p>\n<p>\u4f46\u662f\uff0curl \u4f1a\u6309\u539f\u6837\u4f20\u9012\u5230\u6587\u4ef6\u670d\u52a1\u5668\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u6587\u4ef6\u670d\u52a1\u5668\u6536\u5230\u7528\u6237\u7684\u8bf7\u6c42\uff0c\u8ba4\u4e3a\u7528\u6237\u6b63\u5728\u6839<code>(\".\/static\")<\/code>\u76ee\u5f55\u4e2d\u5bfb\u627e\u540d\u4e3a\u201cstatic\u201d\u7684\u6587\u4ef6\u3002<\/p>\n<p>\u4e8b\u5b9e\u4e0a\uff0c\u5982\u679c\u60a8\u53ea\u662f\u5c06\u4e00\u4e2a\u540d\u4e3a\u201cstatic\u201d\u7684\u6587\u4ef6\u653e\u5728\u201c<code>.\/static<\/code>\u201d\u76ee\u5f55\u4e2d\uff0c\u5219\u8f6c\u5230 <code>...\/static<\/code> \u5c06\u63d0\u4f9b\u8be5\u6587\u4ef6\u3002<\/p>\n<p>\u56e0\u6b64\u4fee\u590d\u9700\u8981\u4e24\u4ef6\u4e8b\uff1a<\/p>\n<ol>\n<li>\u5c06\u8def\u5f84\u524d\u7f00\u66f4\u6539\u4e3a\u201c<code>\/static\/<\/code>\u201d\u800c\u4e0d\u662f\u201c<code>\/static<\/code>\u201d\uff0c\u4ee5\u4fbf\u9759\u6001\u76ee\u5f55\u4e2d\u7684\u6240\u6709\u6587\u4ef6\u90fd\u53ef\u4ee5\u91cd\u65b0\u8def\u7531\u5230\u6587\u4ef6\u670d\u52a1\u5668\uff08\u800c\u4e0d\u4ec5\u4ec5\u662f\u201c\/static\u201d\u8bf7\u6c42\uff09 <\/li>\n<li>\u5728\u5c06\u8bf7\u6c42\u4f20\u9012\u5230\u6587\u4ef6\u670d\u52a1\u5668\u4e4b\u524d\uff0c\u4ece\u8bf7\u6c42\u4e2d\u53bb\u9664\u201c<code>\/static\/<\/code>\u201d\u8def\u5f84\u524d\u7f00\u3002<\/li>\n<\/ol>\n<p>\u50cf\u8fd9\u6837\uff1a<\/p>\n<pre>http.Handle(\"\/static\/\", http.StripPrefix(\"\/static\/\", http.FileServer(http.Dir(\".\/static\"))))<\/pre>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u5982\u4f55\u8c03\u7528\u9759\u6001HTML\u6587\u4ef6\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; \u5982\u4f55\u8c03\u7528\u9759\u6001HTML\u6587\u4ef6 \u5982\u4f55\u8c03\u7528\u9759\u6001HTML\u6587\u4ef6 \u6765\u6e90\uff1astackoverflow 2024-04-20 10:39:38 0\u6d4f\u89c8 \u6536\u85cf IT\u884c\u4e1a\u76f8\u5bf9\u4e8e\u4e00\u822c\u4f20\u7edf\u884c\u4e1a\uff0c\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u66f4\u5feb\uff0c\u4e00\u65e6\u505c\u6b62\u4e86\u5b66\u4e60\uff0c\u5f88\u5feb\u5c31\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u8e0f\u8e0f\u5b9e\u5b9e\u7684\u4e0d\u65ad\u5b66\u4e60\uff0c\u7cbe\u8fdb\u81ea\u5df1\u7684\u6280\u672f\uff0c\u5c24\u5176\u662f\u521d\u5b66\u8005\u3002\u4eca\u5929\u7c73\u4e91\u7ed9\u5927\u5bb6\u6574\u7406\u4e86\u300a\u5982\u4f55\u8c03\u7528\u9759\u6001HTML\u6587\u4ef6\u300b\uff0c\u804a\u804a\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01 \u95ee\u9898\u5185\u5bb9 \u6211\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b index.html \u6587\u4ef6\u7684\u9759\u6001\u6587\u4ef6\u5939\uff0c\u5e76\u5728\u6211\u7684 go \u6587\u4ef6\u4e2d\u5199\u9053\uff1a package main import ( &#8220;net\/http&#8221; ) func main() { http.handle(&#8220;\/&#8221;, http.fileserver(http.dir(&#8220;.\/static&#8221;))) http.listenandserve(&#8220;:8482&#8221;, nil) } \u5728\u63a2\u7d22 http:\/\/localhost:8482\/ \u65f6\u6548\u679c\u5f88\u597d \u6211\u5c1d\u8bd5\u5c06\u4ee3\u7801\u7f16\u5199\u4e3a\uff1a http.Handle(&#8220;\/static&#8221;, http.FileServer(http.Dir(&#8220;.\/static&#8221;))) \u4f46\u662f\u5728\u63a2\u7d22 http:\/\/localhost:8482\/static \u65f6\u5931\u8d25\u5e76\u51fa\u73b0 404 \u9519\u8bef \u89e3\u51b3\u65b9\u6848 http.handle(&#8220;\/static&#8221;, http.fileserver(http.dir(&#8220;.\/static&#8221;))) \u53ea\u662f\u610f\u5473\u7740\uff0c\u201c\u6bcf\u5f53\u6709\u4eba\u8fde\u63a5\u5230 &#8230;\/static \u65f6\uff0c\u5c06\u6574\u4e2a\u8bf7\u6c42\u91cd\u65b0\u8def\u7531\u5230\u6587\u4ef6\u670d\u52a1\u5668\u6839\u76ee\u5f55\u4e3a .\/static&#8221;\u3002 \u4f46\u662f\uff0curl \u4f1a\u6309\u539f\u6837\u4f20\u9012\u5230\u6587\u4ef6\u670d\u52a1\u5668\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u6587\u4ef6\u670d\u52a1\u5668\u6536\u5230\u7528\u6237\u7684\u8bf7\u6c42\uff0c\u8ba4\u4e3a\u7528\u6237\u6b63\u5728\u6839(&#8220;.\/static&#8221;)\u76ee\u5f55\u4e2d\u5bfb\u627e\u540d\u4e3a\u201cstatic\u201d\u7684\u6587\u4ef6\u3002 \u4e8b\u5b9e\u4e0a\uff0c\u5982\u679c\u60a8\u53ea\u662f\u5c06\u4e00\u4e2a\u540d\u4e3a\u201cstatic\u201d\u7684\u6587\u4ef6\u653e\u5728\u201c.\/static\u201d\u76ee\u5f55\u4e2d\uff0c\u5219\u8f6c\u5230 &#8230;\/static [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-41448","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/41448","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=41448"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/41448\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=41448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=41448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=41448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}