{"id":18072,"date":"2024-11-18T15:50:39","date_gmt":"2024-11-18T07:50:39","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18072\/"},"modified":"2024-11-18T15:50:39","modified_gmt":"2024-11-18T07:50:39","slug":"nginx%e6%80%8e%e4%b9%88%e9%83%a8%e7%bd%b2vue%e9%a1%b9%e7%9b%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18072\/","title":{"rendered":"nginx\u600e\u4e48\u90e8\u7f72vue\u9879\u76ee"},"content":{"rendered":"<blockquote><p>\n  \u5c06 vue \u9879\u76ee\u90e8\u7f72\u5230 nginx \u53ef\u63d0\u4f9b\u751f\u4ea7\u73af\u5883\u90e8\u7f72\u7684\u9ad8\u6027\u80fd\u3002\u6b65\u9aa4\u5305\u62ec\uff1a\u6784\u5efa vue \u9879\u76ee\uff1a\u8fd0\u884c npm\/yarn build\u3002\u914d\u7f6e nginx\uff1a\u521b\u5efa\u865a\u62df\u4e3b\u673a\u5757\uff0croot \u6307\u5411 dist \u6587\u4ef6\u5939\uff0cindex \u8bbe\u7f6e\u4e3a\u5165\u53e3\u70b9\u6587\u4ef6\u3002\u542f\u52a8 nginx\uff1a\u91cd\u65b0\u52a0\u8f7d\/\u542f\u52a8 nginx\u3002\u8bbf\u95ee\u5e94\u7528\u7a0b\u5e8f\uff1a\u901a\u8fc7\u865a\u62df\u4e3b\u673a\u540d\u8bbf\u95ee\u90e8\u7f72\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/27\/2024052722062089416.jpg\" class=\"aligncenter\" title=\"nginx\u600e\u4e48\u90e8\u7f72vue\u9879\u76ee\u63d2\u56fe\" alt=\"nginx\u600e\u4e48\u90e8\u7f72vue\u9879\u76ee\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06 Vue \u9879\u76ee\u90e8\u7f72\u5230 Nginx<\/strong><\/p>\n<p><strong>\u5f00\u95e8\u89c1\u5c71<\/strong>\uff1a<br \/>\u5c06 Vue \u9879\u76ee\u90e8\u7f72\u5230 Nginx \u662f\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u6258\u7ba1\u548c\u63d0\u4f9b Vue \u5e94\u7528\u7a0b\u5e8f\u7684\u4e00\u79cd\u5e38\u89c1\u505a\u6cd5\u3002<\/p>\n<p><strong>\u8be6\u7ec6\u6b65\u9aa4<\/strong>\uff1a<\/p>\n<p><strong>1. \u6784\u5efa Vue \u9879\u76ee<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>\u8fd0\u884c npm run build \u6216 yarn build \u6765\u6784\u5efa Vue \u9879\u76ee\u3002<\/li>\n<li>\u6784\u5efa\u8fc7\u7a0b\u5c06\u521b\u5efa\u5305\u542b\u60a8\u7684\u9759\u6001\u6587\u4ef6\uff08html\u3001\u3001js\uff09\u7684 dist \u6587\u4ef6\u5939\u3002<\/li>\n<\/ul>\n<p><strong>2. \u914d\u7f6e Nginx<\/strong><\/p>\n<ul>\n<li>\u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u865a\u62df\u4e3b\u673a\u5757\u3002<\/li>\n<li>\u5c06 root \u6307\u4ee4\u6307\u5411\u6784\u5efa\u7684 dist \u6587\u4ef6\u5939\u3002<\/li>\n<li>\u5c06 index \u6307\u4ee4\u8bbe\u7f6e\u4e3a\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u5165\u53e3\u70b9\u6587\u4ef6\uff0c\u901a\u5e38\u662f index.html\u3002<\/li>\n<\/ul>\n<p>\u793a\u4f8b\u914d\u7f6e\uff1a<\/p>\n<pre>server {\n  listen 80;\n  server_name example.com;\n  root \/path\/to\/your-vue-project\/dist;\n  index index.html;\n  location \/ {\n    try_files $uri $uri\/ \/index.html;\n  }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u542f\u52a8 Nginx<\/strong><\/p>\n<ul>\n<li>\u91cd\u65b0\u52a0\u8f7d\u6216\u542f\u52a8 Nginx\u3002<\/li>\n<li>\u60a8\u53ef\u4ee5\u4f7f\u7528  -t \u68c0\u67e5 Nginx \u914d\u7f6e\u662f\u5426\u6709\u8bed\u6cd5\u9519\u8bef\u3002<\/li>\n<li>\u4f7f\u7528 nginx -s reload \u91cd\u65b0\u52a0\u8f7d Nginx\u3002<\/li>\n<\/ul>\n<p><strong>4. \u8bbf\u95ee\u5e94\u7528\u7a0b\u5e8f<\/strong><\/p>\n<ul>\n<li>\u5728\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95ee example.com \u6216\u60a8\u7684\u865a\u62df\u4e3b\u673a\u540d\u3002<\/li>\n<li>\u60a8\u73b0\u5728\u5e94\u8be5\u80fd\u591f\u770b\u5230\u90e8\u7f72\u7684 Vue \u5e94\u7528\u7a0b\u5e8f\u3002<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528 Nginx \u90e8\u7f72 Vue \u9879\u76ee\u7684\u4f18\u70b9<\/strong>\uff1a<\/p>\n<ul>\n<li>\u901f\u5ea6\u5feb\uff0c\u6027\u80fd\u9ad8<\/li>\n<li>\u53ef\u6269\u5c55\u6027\u548c\u9ad8\u53ef\u7528\u6027<\/li>\n<li>SSL\/TLS \u652f\u6301\uff0c\u7528\u4e8e\u5b89\u5168\u8fde\u63a5<\/li>\n<li>\u53cd\u5411\u4ee3\u7406\u548c\u8d1f\u8f7d\u5e73\u8861\u529f\u80fd<\/li>\n<li>\u652f\u6301\u591a\u79cd\u7f13\u5b58\u7b56\u7565<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u90e8\u7f72\u9879\u76ee\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c06 vue \u9879\u76ee\u90e8\u7f72\u5230 nginx \u53ef\u63d0\u4f9b\u751f\u4ea7\u73af\u5883\u90e8\u7f72\u7684\u9ad8\u6027\u80fd\u3002\u6b65\u9aa4\u5305\u62ec\uff1a\u6784\u5efa vue \u9879\u76ee\uff1a\u8fd0\u884c npm\/yarn build\u3002\u914d\u7f6e nginx\uff1a\u521b\u5efa\u865a\u62df\u4e3b\u673a\u5757\uff0croot \u6307\u5411 dist \u6587\u4ef6\u5939\uff0cindex \u8bbe\u7f6e\u4e3a\u5165\u53e3\u70b9\u6587\u4ef6\u3002\u542f\u52a8 nginx\uff1a\u91cd\u65b0\u52a0\u8f7d\/\u542f\u52a8 nginx\u3002\u8bbf\u95ee\u5e94\u7528\u7a0b\u5e8f\uff1a\u901a\u8fc7\u865a\u62df\u4e3b\u673a\u540d\u8bbf\u95ee\u90e8\u7f72\u7684\u5e94\u7528\u7a0b\u5e8f\u3002 \u5982\u4f55\u5c06 Vue \u9879\u76ee\u90e8\u7f72\u5230 Nginx \u5f00\u95e8\u89c1\u5c71\uff1a\u5c06 Vue \u9879\u76ee\u90e8\u7f72\u5230 Nginx \u662f\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u6258\u7ba1\u548c\u63d0\u4f9b Vue \u5e94\u7528\u7a0b\u5e8f\u7684\u4e00\u79cd\u5e38\u89c1\u505a\u6cd5\u3002 \u8be6\u7ec6\u6b65\u9aa4\uff1a 1. \u6784\u5efa Vue \u9879\u76ee \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u8fd0\u884c npm run build \u6216 yarn build \u6765\u6784\u5efa Vue \u9879\u76ee\u3002 \u6784\u5efa\u8fc7\u7a0b\u5c06\u521b\u5efa\u5305\u542b\u60a8\u7684\u9759\u6001\u6587\u4ef6\uff08html\u3001\u3001js\uff09\u7684 dist \u6587\u4ef6\u5939\u3002 2. \u914d\u7f6e Nginx \u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u865a\u62df\u4e3b\u673a\u5757\u3002 \u5c06 root \u6307\u4ee4\u6307\u5411\u6784\u5efa\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-18072","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18072","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=18072"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18072\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}