{"id":848,"date":"2021-08-31T22:02:29","date_gmt":"2021-08-31T14:02:29","guid":{"rendered":"https:\/\/www.dd-home.top\/?p=848"},"modified":"2021-08-31T22:02:29","modified_gmt":"2021-08-31T14:02:29","slug":"vue-%e6%90%ba%e5%b8%a6%e9%a1%b9%e7%9b%ae%e5%90%8d%e9%83%a8%e7%bd%b2%e5%9c%a8nginx%e4%b8%ad","status":"publish","type":"post","link":"https:\/\/www.dd-home.top\/?p=848","title":{"rendered":"Vue \u643a\u5e26\u9879\u76ee\u540d\u90e8\u7f72\u5728Nginx\u4e2d"},"content":{"rendered":"<p><!--more--><\/p>\n<h4 class=\"md-end-block md-heading\"><span class=\"md-plain md-expand\">1\u3001\u573a\u666f<\/span><\/h4>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">Nginx\u9879\u76ee\u90e8\u7f72vue \u9879\u76ee\u65f6\u9700\u8981\u643a\u5e26\u9879\u76ee\u540d\u79f0\u3002<\/span><\/p>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">\u4f8b\u5982 <\/span><span class=\"md-link md-pair-s\" spellcheck=\"false\"><a href=\"http:\/\/www.abc.com\/project_name\/\">http:\/\/www.abc.com\/project_name\/<\/a><\/span><\/p>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">\u6b64\u65f6\u9700\u8981\u5728vue\u9879\u76ee\u4e2d\u548cnginx.conf\u6587\u4ef6\u4e2d\u8fdb\u884c\u4fee\u6539<\/span><\/p>\n<p class=\"md-end-block md-p\">\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">\u4ee5\u4e0b\u6211\u81ea\u5df1\u5c1d\u8bd5\u4e86\uff0c\u53ef\u80fd\u6709\u5176\u4ed6\u7684\u65b9\u5f0f\u3002<\/span><\/p>\n<p class=\"md-end-block md-p\">\n<h4 class=\"md-end-block md-heading\"><span class=\"md-plain\">2\u3001Vue\u9879\u76ee\u8c03\u6574\u7684\u5730\u65b9<\/span><\/h4>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">router\u6587\u4ef6\u5939\u4e0b index.js<\/span><\/p>\n<pre class=\"md-fences md-end-block ty-contain-cm modeLoaded\" lang=\"vue\" spellcheck=\"false\"><span role=\"presentation\">const createRouter = () =&gt; new Router({<\/span>\r\n<span role=\"presentation\">  \/\/ mode: 'history', \/\/ require service support<\/span>\r\n<span role=\"presentation\">  mode: 'history',\/\/ \u65b0\u589e<\/span>\r\n<span role=\"presentation\">  base: '\/project_name\/',\/\/\u65b0\u589e<\/span>\r\n<span role=\"presentation\">  scrollBehavior: () =&gt; ({ y: 0 }),<\/span>\r\n<span role=\"presentation\">  routes: constantRouter<\/span>\r\n<span role=\"presentation\">})<\/span><\/pre>\n<p class=\"md-end-block md-p\">\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">\u4fee\u6539vue.config.js<\/span><\/p>\n<pre class=\"md-fences md-end-block ty-contain-cm modeLoaded\" lang=\"\" spellcheck=\"false\"><span role=\"presentation\">publicPath: '\/project_name\/' <\/span><\/pre>\n<p class=\"md-end-block md-p\">\n<h4 class=\"md-end-block md-heading\"><span class=\"md-plain\">3\u3001Nginx\u9879\u76ee\u4fee\u6539\u7684\u5730\u65b9<\/span><\/h4>\n<pre class=\"md-fences md-end-block ty-contain-cm modeLoaded\" lang=\"html\" spellcheck=\"false\"><span role=\"presentation\">1.\u7f16\u8bd1\u540e\u7684vue dist \u590d\u5236\u5230nginx\u6587\u4ef6\u5939\u4e2d\uff0c\u6309\u7167\u4e2a\u4eba\u559c\u597d<\/span>\r\n<span role=\"presentation\">\u200b<\/span>\r\n<span role=\"presentation\">\u6211\u7684\u65b9\u5f0f\u5982\u4e0b\uff1a<\/span>\r\n<span role=\"presentation\">\/nginx\/html\/project_name\/dist\u4e2d\u7684\u6587\u4ef6<\/span><\/pre>\n<p class=\"md-end-block md-p md-focus\"><span class=\"md-plain md-expand\">nginx.conf \u6587\u4ef6\u4e2d\u7684server\u4e2d\u4fee\u6539<\/span><\/p>\n<pre class=\"md-fences md-end-block ty-contain-cm modeLoaded\" lang=\"shell\" spellcheck=\"false\"><span role=\"presentation\">location \/project_name\/ {<\/span>\r\n<span role=\"presentation\"> \u00a0  root \u00a0 html;<\/span>\r\n<span role=\"presentation\"> \u00a0  index  index.html index.htm;<\/span>\r\n<span role=\"presentation\"> \u00a0  try_files <span class=\"cm-def\">$uri<\/span> <span class=\"cm-def\">$uri<\/span>\/ @router;<\/span>\r\n<span role=\"presentation\">}<\/span>\r\n<span role=\"presentation\">     \u00a0 \u00a0<\/span>\r\n<span role=\"presentation\">location @router {<\/span>\r\n<span role=\"presentation\"> \u00a0  rewrite ^.*<span class=\"cm-def\">$ <\/span>\/project_name\/index.html last;<\/span>\r\n<span role=\"presentation\">}<\/span>\r\n<span role=\"presentation\">\u200b<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6],"tags":[67],"class_list":["post-848","post","type-post","status-publish","format-standard","hentry","category-5","category-6","tag-vue"],"_links":{"self":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts\/848","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=848"}],"version-history":[{"count":1,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts\/848\/revisions"}],"predecessor-version":[{"id":849,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts\/848\/revisions\/849"}],"wp:attachment":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}