{"id":41137,"date":"2025-05-31T07:10:44","date_gmt":"2025-05-30T23:10:44","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/41137.html"},"modified":"2025-05-31T07:10:44","modified_gmt":"2025-05-30T23:10:44","slug":"%e5%a6%82%e4%bd%95%e5%b0%86vue2%e4%bd%bf%e7%94%a8npm-run-build%e6%89%93%e5%8c%85%e5%a5%bd%e7%9a%84%e6%96%87%e4%bb%b6%e4%b8%8a%e4%bc%a0%e5%88%b0%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/41137.html","title":{"rendered":"\u5982\u4f55\u5c06vue2\u4f7f\u7528npm run build\u6253\u5305\u597d\u7684\u6587\u4ef6\u4e0a\u4f20\u5230\u670d\u52a1\u5668"},"content":{"rendered":"<p>\u8981\u5c06 Vue 2 \u9879\u76ee\u6253\u5305\u5e76\u90e8\u7f72\u5230\u670d\u52a1\u5668\u4e0a&#xff0c;\u5e76\u4f7f\u7528 Nginx \u4f5c\u4e3a Web \u670d\u52a1\u5668&#xff0c;\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c&#xff1a;<\/p>\n<h4>1. \u6253\u5305 Vue 2 \u9879\u76ee<\/h4>\n<p>\u9996\u5148&#xff0c;\u786e\u4fdd\u4f60\u7684 Vue 2 \u9879\u76ee\u5df2\u7ecf\u5f00\u53d1\u5b8c\u6210&#xff0c;\u5e76\u4e14\u53ef\u4ee5\u5728\u672c\u5730\u6b63\u5e38\u8fd0\u884c\u3002\u7136\u540e\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u6253\u5305&#xff1a;<\/p>\n<p>npm run build<\/p>\n<p>\u6253\u5305\u5b8c\u6210\u540e&#xff0c;\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u4f1a\u751f\u6210\u4e00\u4e2a\u00a0dist\u00a0\u6587\u4ef6\u5939&#xff0c;\u91cc\u9762\u5305\u542b\u4e86\u6240\u6709\u9759\u6001\u6587\u4ef6&#xff08;HTML\u3001CSS\u3001JS \u7b49&#xff09;\u3002<\/p>\n<h4>2. \u5c06\u6253\u5305\u6587\u4ef6\u4e0a\u4f20\u5230\u670d\u52a1\u5668<\/h4>\n<p>\u4f60\u53ef\u4ee5\u4f7f\u7528\u00a0scp\u3001rsync\u00a0\u6216\u8005 FTP \u5de5\u5177\u5c06\u00a0dist\u00a0\u6587\u4ef6\u5939\u4e0a\u4f20\u5230\u670d\u52a1\u5668\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528\u00a0scp\u00a0\u7684\u793a\u4f8b&#xff1a;<\/p>\n<p>scp -r dist\/ user&#064;your_server_ip:\/path\/to\/your\/project<\/p>\n<ul>\n<li>\n<p>user\u00a0\u662f\u4f60\u7684\u670d\u52a1\u5668\u7528\u6237\u540d\u3002<\/p>\n<\/li>\n<li>\n<p>your_server_ip\u00a0\u662f\u4f60\u7684\u670d\u52a1\u5668 IP \u5730\u5740\u3002<\/p>\n<\/li>\n<li>\n<p>\/path\/to\/your\/project\u00a0\u662f\u4f60\u5e0c\u671b\u5c06\u6587\u4ef6\u4e0a\u4f20\u5230\u7684\u670d\u52a1\u5668\u76ee\u5f55\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>3. \u5b89\u88c5\u548c\u914d\u7f6e Nginx<\/h4>\n<p>\u5982\u679c\u670d\u52a1\u5668\u4e0a\u8fd8\u6ca1\u6709\u5b89\u88c5 Nginx&#xff0c;\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5&#xff1a;<\/p>\n<h5>\u5bf9\u4e8e Ubuntu\/Debian \u7cfb\u7edf&#xff1a;<\/h5>\n<p>sudo apt update<\/p>\n<p>sudo apt install nginx<\/p>\n<h5>\u5bf9\u4e8e CentOS\/RHEL \u7cfb\u7edf&#xff1a;<\/h5>\n<p>sudo yum install nginx<\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e&#xff0c;\u542f\u52a8 Nginx \u5e76\u8bbe\u7f6e\u4e3a\u5f00\u673a\u81ea\u542f&#xff1a;<\/p>\n<p>sudo systemctl start nginx<\/p>\n<p>sudo systemctl enable nginx<\/p>\n<h4>4. \u914d\u7f6e Nginx \u4ee5\u670d\u52a1 Vue \u5e94\u7528<\/h4>\n<p>\u63a5\u4e0b\u6765&#xff0c;\u4f60\u9700\u8981\u914d\u7f6e Nginx \u6765\u670d\u52a1\u4f60\u7684 Vue \u5e94\u7528\u3002\u7f16\u8f91 Nginx \u7684\u914d\u7f6e\u6587\u4ef6&#xff1a;<\/p>\n<p>sudo nano \/etc\/nginx\/sites-available\/your_project<\/p>\n<p>\u5728\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9&#xff1a;<\/p>\n<p>server {<\/p>\n<p>    listen 82;<\/p>\n<p>    server_name your_domain_or_ip;<\/p>\n<p>    root \/path\/to\/your\/project\/dist;<\/p>\n<p>    index index.html;<\/p>\n<p>    location \/ {<\/p>\n<p>        try_files $uri $uri\/ \/index.html;<\/p>\n<p>    }<\/p>\n<p>    location \/api\/ {<\/p>\n<p>        proxy_pass http:\/\/your_backend_server;<\/p>\n<p>        proxy_set_header Host $host;<\/p>\n<p>        proxy_set_header X-Real-IP $remote_addr;<\/p>\n<p>        proxy_set_header REMOTE-HOST $remote_addr;<\/p>\n<p>        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<\/p>\n<p>        proxy_set_header X-Forwarded-Proto $scheme;<\/p>\n<p>        add_header Access-Control-Allow-Methods *;<\/p>\n<p>        add_header Access-Control-Allow-Origin $http_origin;<\/p>\n<p>    }<\/p>\n<p>    error_page 500 502 503 504 \/50x.html;<\/p>\n<p>    location &#061; \/50x.html {<\/p>\n<p>        root \/usr\/share\/nginx\/html;<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<ul>\n<li>\n<p>listen xx, xx\u662f\u4f60\u7684\u76d1\u542c\u7aef\u53e3<\/p>\n<\/li>\n<li>\n<p>your_domain_or_ip\u00a0\u662f\u4f60\u7684\u57df\u540d\u6216\u670d\u52a1\u5668 IP \u5730\u5740\u3002<\/p>\n<\/li>\n<li>\n<p>\/path\/to\/your\/project\/dist\u00a0\u662f\u4f60\u4e0a\u4f20\u7684\u00a0dist\u00a0\u6587\u4ef6\u5939\u7684\u8def\u5f84\u3002<\/p>\n<\/li>\n<li>\n<p>your_backend_server\u00a0\u662f\u540e\u7aef API \u670d\u52a1\u5668\u5730\u5740&#xff08;\u5982\u679c\u6709\u7684\u8bdd&#xff09;\u3002\/api\/\u4ee3\u8868\u5339\u914d\u524d\u7aef\u554abaseURL&#061;&#039;\/api&#039;\u7684\u65f6\u5019\u3002\u4f8b\u5982&#xff1a;proxy_pass\u00a0http:\/\/127.0.0.1:8002\/api\/;<\/p>\n<\/li>\n<\/ul>\n<p>\u4fdd\u5b58\u5e76\u9000\u51fa\u7f16\u8f91\u5668\u3002<\/p>\n<h4>5. \u542f\u7528 Nginx \u914d\u7f6e<\/h4>\n<p>\u521b\u5efa\u4e00\u4e2a\u7b26\u53f7\u94fe\u63a5\u6765\u542f\u7528\u8be5\u914d\u7f6e\u6587\u4ef6&#xff1a;<\/p>\n<p>sudo ln -s \/etc\/nginx\/sites-available\/your_project \/etc\/nginx\/sites-enabled\/<\/p>\n<p>\u7136\u540e\u6d4b\u8bd5 Nginx \u914d\u7f6e\u662f\u5426\u6b63\u786e&#xff1a;<\/p>\n<p>sudo nginx -t<\/p>\n<p>\u5982\u679c\u914d\u7f6e\u6b63\u786e&#xff0c;\u91cd\u65b0\u52a0\u8f7d Nginx&#xff1a;<\/p>\n<p>sudo systemctl reload nginx<\/p>\n<h4>6. \u8bbf\u95ee\u4f60\u7684 Vue \u5e94\u7528<\/h4>\n<p>\u73b0\u5728&#xff0c;\u4f60\u53ef\u4ee5\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95ee\u4f60\u7684 Vue \u5e94\u7528\u4e86\u3002\u5728\u5730\u5740\u680f\u4e2d\u8f93\u5165\u4f60\u7684\u57df\u540d\u6216\u670d\u52a1\u5668 IP \u5730\u5740&#xff0c;\u5e94\u8be5\u5c31\u80fd\u770b\u5230\u4f60\u7684 Vue \u5e94\u7528\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<h4>7. &#xff08;\u53ef\u9009&#xff09;\u914d\u7f6e HTTPS<\/h4>\n<p>\u5982\u679c\u4f60\u6709\u57df\u540d\u5e76\u4e14\u5e0c\u671b\u542f\u7528 HTTPS&#xff0c;\u53ef\u4ee5\u4f7f\u7528 Let&#039;s Encrypt \u514d\u8d39 SSL \u8bc1\u4e66\u3002\u5b89\u88c5 Certbot \u5e76\u83b7\u53d6\u8bc1\u4e66&#xff1a;<\/p>\n<p>sudo apt install certbot python3-certbot-nginx<\/p>\n<p>sudo certbot &#8211;nginx -d your_domain<\/p>\n<p>\u6309\u7167\u63d0\u793a\u64cd\u4f5c&#xff0c;Certbot \u4f1a\u81ea\u52a8\u914d\u7f6e Nginx \u4ee5\u4f7f\u7528 HTTPS\u3002<\/p>\n<h4>\u603b\u7ed3<\/h4>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4&#xff0c;\u4f60\u5df2\u7ecf\u6210\u529f\u5c06 Vue 2 \u9879\u76ee\u6253\u5305\u5e76\u90e8\u7f72\u5230\u670d\u52a1\u5668\u4e0a&#xff0c;\u4f7f\u7528 Nginx \u4f5c\u4e3a Web \u670d\u52a1\u5668\u3002\u5982\u679c\u6709\u4efb\u4f55\u95ee\u9898&#xff0c;\u53ef\u4ee5\u68c0\u67e5 Nginx \u7684\u65e5\u5fd7\u6587\u4ef6&#xff08;\u901a\u5e38\u4f4d\u4e8e\u00a0\/var\/log\/nginx\/error.log&#xff09;\u6765\u6392\u67e5\u9519\u8bef\u3002<\/p>\n<hr \/>\n<p>\u914d\u7f6e Nginx \u4ee5\u670d\u52a1 Vue \u5e94\u7528\u7684\u6838\u5fc3\u662f\u901a\u8fc7 Nginx \u5c06\u7528\u6237\u7684\u8bf7\u6c42\u6b63\u786e\u5730\u6307\u5411 Vue \u5e94\u7528\u7684\u9759\u6001\u6587\u4ef6&#xff08;\u5982\u00a0index.html\u3001JavaScript\u3001CSS \u7b49&#xff09;&#xff0c;\u5e76\u786e\u4fdd Vue \u7684\u8def\u7531&#xff08;\u5982 Vue Router&#xff09;\u80fd\u591f\u6b63\u5e38\u5de5\u4f5c\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u7684\u6b65\u9aa4\u548c\u89e3\u91ca&#xff1a;<\/p>\n<hr \/>\n<h4>1.\u00a0Nginx \u914d\u7f6e\u6587\u4ef6\u7684\u57fa\u672c\u7ed3\u6784<\/h4>\n<p>Nginx \u7684\u914d\u7f6e\u6587\u4ef6\u901a\u5e38\u4f4d\u4e8e\u00a0\/etc\/nginx\/nginx.conf\u00a0\u6216\u00a0\/etc\/nginx\/sites-available\/\u00a0\u76ee\u5f55\u4e0b\u3002\u6bcf\u4e2a\u7ad9\u70b9&#xff08;\u6216\u5e94\u7528&#xff09;\u901a\u5e38\u6709\u4e00\u4e2a\u72ec\u7acb\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5178\u578b\u7684 Nginx \u914d\u7f6e\u6587\u4ef6\u793a\u4f8b&#xff0c;\u7528\u4e8e\u670d\u52a1 Vue \u5e94\u7528&#xff1a;<\/p>\n<p>server {<\/p>\n<p>    # \u76d1\u542c\u7aef\u53e3&#xff08;HTTP \u9ed8\u8ba4\u662f 80&#xff0c;HTTPS \u9ed8\u8ba4\u662f 443&#xff09;<\/p>\n<p>    listen 80;<\/p>\n<p>    # \u670d\u52a1\u5668\u57df\u540d\u6216 IP \u5730\u5740<\/p>\n<p>    server_name your_domain_or_ip;<\/p>\n<p>    # Vue \u5e94\u7528\u7684\u9759\u6001\u6587\u4ef6\u8def\u5f84<\/p>\n<p>    root \/path\/to\/your\/project\/dist;<\/p>\n<p>    # \u9ed8\u8ba4\u8bbf\u95ee\u7684\u6587\u4ef6<\/p>\n<p>    index index.html;<\/p>\n<p>    # \u5904\u7406\u6839\u8def\u5f84\u8bf7\u6c42<\/p>\n<p>    location \/ {<\/p>\n<p>        # \u5c1d\u8bd5\u6309\u987a\u5e8f\u67e5\u627e\u6587\u4ef6\u6216\u76ee\u5f55&#xff0c;\u5982\u679c\u627e\u4e0d\u5230\u5219\u8fd4\u56de index.html<\/p>\n<p>        try_files $uri $uri\/ \/index.html;<\/p>\n<p>    }<\/p>\n<p>    # \u5904\u7406 API \u8bf7\u6c42&#xff08;\u5982\u679c\u6709\u540e\u7aef\u670d\u52a1&#xff09;<\/p>\n<p>    location \/api\/ {<\/p>\n<p>        # \u5c06\u8bf7\u6c42\u4ee3\u7406\u5230\u540e\u7aef\u670d\u52a1\u5668<\/p>\n<p>        proxy_pass http:\/\/your_backend_server;<\/p>\n<p>        proxy_set_header Host $host;<\/p>\n<p>        proxy_set_header X-Real-IP $remote_addr;<\/p>\n<p>        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<\/p>\n<p>        proxy_set_header X-Forwarded-Proto $scheme;<\/p>\n<p>    }<\/p>\n<p>    # \u5904\u7406 50x \u9519\u8bef\u9875\u9762<\/p>\n<p>    error_page 500 502 503 504 \/50x.html;<\/p>\n<p>    location &#061; \/50x.html {<\/p>\n<p>        root \/usr\/share\/nginx\/html;<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<hr \/>\n<h4>2.\u00a0\u5173\u952e\u914d\u7f6e\u9879\u8be6\u89e3<\/h4>\n<h5>1.\u00a0listen<\/h5>\n<ul>\n<li>\n<p>\u6307\u5b9a Nginx \u76d1\u542c\u7684\u7aef\u53e3\u53f7\u3002<\/p>\n<\/li>\n<li>\n<p>HTTP \u9ed8\u8ba4\u7aef\u53e3\u662f\u00a080&#xff0c;HTTPS \u9ed8\u8ba4\u7aef\u53e3\u662f\u00a0443\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>listen 80;\n <\/li>\n<\/ul>\n<h5>2.\u00a0server_name<\/h5>\n<ul>\n<li>\n<p>\u6307\u5b9a\u670d\u52a1\u5668\u7684\u57df\u540d\u6216 IP \u5730\u5740\u3002<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u4f7f\u7528\u57df\u540d&#xff0c;\u9700\u8981\u786e\u4fdd\u57df\u540d\u5df2\u7ecf\u89e3\u6790\u5230\u670d\u52a1\u5668\u7684 IP \u5730\u5740\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>server_name example.com;<\/p>\n<p>\u6216\u8005&#xff1a;<\/p>\n<p>server_name 192.168.1.100;\n <\/li>\n<\/ul>\n<h5>3.\u00a0root<\/h5>\n<ul>\n<li>\n<p>\u6307\u5b9a Vue \u5e94\u7528\u9759\u6001\u6587\u4ef6\u7684\u6839\u76ee\u5f55\u3002<\/p>\n<\/li>\n<li>\n<p>\u8fd9\u662f Vue \u6253\u5305\u540e\u751f\u6210\u7684\u00a0dist\u00a0\u6587\u4ef6\u5939\u7684\u8def\u5f84\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>root \/var\/www\/vue-app\/dist;\n <\/li>\n<\/ul>\n<h5>4.\u00a0index<\/h5>\n<ul>\n<li>\n<p>\u6307\u5b9a\u9ed8\u8ba4\u8bbf\u95ee\u7684\u6587\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p>\u5bf9\u4e8e Vue \u5e94\u7528&#xff0c;\u901a\u5e38\u662f\u00a0index.html\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>index index.html;\n <\/li>\n<\/ul>\n<h5>5.\u00a0location \/<\/h5>\n<ul>\n<li>\n<p>\u5904\u7406\u6839\u8def\u5f84&#xff08;\/&#xff09;\u7684\u8bf7\u6c42\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u00a0try_files\u00a0\u6307\u4ee4\u6765\u5c1d\u8bd5\u67e5\u627e\u6587\u4ef6\u6216\u76ee\u5f55&#xff0c;\u5982\u679c\u627e\u4e0d\u5230\u5219\u8fd4\u56de\u00a0index.html\u3002<\/p>\n<\/li>\n<li>\n<p>\u8fd9\u662f\u4e3a\u4e86\u652f\u6301 Vue Router \u7684\u8def\u7531\u529f\u80fd&#xff0c;\u786e\u4fdd\u7528\u6237\u5728\u76f4\u63a5\u8bbf\u95ee\u975e\u6839\u8def\u5f84\u65f6&#xff08;\u5982\u00a0\/about&#xff09;&#xff0c;Nginx \u4e5f\u80fd\u6b63\u786e\u8fd4\u56de\u00a0index.html&#xff0c;\u7531 Vue \u5e94\u7528\u5904\u7406\u8def\u7531\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>location \/ {<\/p>\n<p>    try_files $uri $uri\/ \/index.html;<\/p>\n<p>}\n <\/li>\n<\/ul>\n<h5>6.\u00a0location \/api\/<\/h5>\n<ul>\n<li>\n<p>\u5982\u679c\u4f60\u7684 Vue \u5e94\u7528\u9700\u8981\u4e0e\u540e\u7aef API \u901a\u4fe1&#xff0c;\u53ef\u4ee5\u901a\u8fc7 Nginx \u5c06 API \u8bf7\u6c42\u4ee3\u7406\u5230\u540e\u7aef\u670d\u52a1\u5668\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>location \/api\/ {<\/p>\n<p>    proxy_pass http:\/\/your_backend_server;<\/p>\n<p>    proxy_set_header Host $host;<\/p>\n<p>    proxy_set_header X-Real-IP $remote_addr;<\/p>\n<p>    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<\/p>\n<p>    proxy_set_header X-Forwarded-Proto $scheme;<\/p>\n<p>}<\/p>\n<ul>\n<li>\n<p>proxy_pass&#xff1a;\u5c06\u8bf7\u6c42\u8f6c\u53d1\u5230\u540e\u7aef\u670d\u52a1\u5668\u3002<\/p>\n<\/li>\n<li>\n<p>proxy_set_header&#xff1a;\u8bbe\u7f6e\u8bf7\u6c42\u5934&#xff0c;\u786e\u4fdd\u540e\u7aef\u670d\u52a1\u5668\u80fd\u591f\u83b7\u53d6\u6b63\u786e\u7684\u5ba2\u6237\u7aef\u4fe1\u606f\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5>7.\u00a0error_page<\/h5>\n<ul>\n<li>\n<p>\u5b9a\u4e49\u9519\u8bef\u9875\u9762\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f8b\u5982&#xff0c;\u5f53\u670d\u52a1\u5668\u51fa\u73b0 500\u3001502\u3001503 \u6216 504 \u9519\u8bef\u65f6&#xff0c;\u8fd4\u56de\u00a0\/50x.html\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>error_page 500 502 503 504 \/50x.html;<\/p>\n<p>location &#061; \/50x.html {<\/p>\n<p>    root \/usr\/share\/nginx\/html;<\/p>\n<p>}\n <\/li>\n<\/ul>\n<hr \/>\n<h4>3.\u00a0\u5b8c\u6574\u7684\u914d\u7f6e\u793a\u4f8b<\/h4>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5b8c\u6574\u7684 Nginx \u914d\u7f6e\u6587\u4ef6\u793a\u4f8b&#xff0c;\u9002\u7528\u4e8e\u670d\u52a1 Vue \u5e94\u7528&#xff1a;<\/p>\n<p>server {<\/p>\n<p>    listen 80;<\/p>\n<p>    server_name example.com;<\/p>\n<p>    root \/var\/www\/vue-app\/dist;<\/p>\n<p>    index index.html;<\/p>\n<p>    location \/ {<\/p>\n<p>        try_files $uri $uri\/ \/index.html;<\/p>\n<p>    }<\/p>\n<p>    location \/api\/ {<\/p>\n<p>        proxy_pass http:\/\/backend_server;<\/p>\n<p>        proxy_set_header Host $host;<\/p>\n<p>        proxy_set_header X-Real-IP $remote_addr;<\/p>\n<p>        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<\/p>\n<p>        proxy_set_header X-Forwarded-Proto $scheme;<\/p>\n<p>    }<\/p>\n<p>    error_page 500 502 503 504 \/50x.html;<\/p>\n<p>    location &#061; \/50x.html {<\/p>\n<p>        root \/usr\/share\/nginx\/html;<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<hr \/>\n<h4>4.\u00a0\u542f\u7528\u914d\u7f6e<\/h4>\n<li>\n<p>\u5c06\u914d\u7f6e\u6587\u4ef6\u4fdd\u5b58\u5230\u00a0\/etc\/nginx\/sites-available\/\u00a0\u76ee\u5f55\u4e0b&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<p>sudo nano \/etc\/nginx\/sites-available\/vue-app\n <\/li>\n<li>\n<p>\u521b\u5efa\u4e00\u4e2a\u7b26\u53f7\u94fe\u63a5\u5230\u00a0\/etc\/nginx\/sites-enabled\/\u00a0\u76ee\u5f55&#xff1a;<\/p>\n<p>sudo ln -s \/etc\/nginx\/sites-available\/vue-app \/etc\/nginx\/sites-enabled\/\n <\/li>\n<li>\n<p>\u6d4b\u8bd5 Nginx \u914d\u7f6e\u662f\u5426\u6b63\u786e&#xff1a;<\/p>\n<p>sudo nginx -t\n <\/li>\n<li>\n<p>\u5982\u679c\u6d4b\u8bd5\u901a\u8fc7&#xff0c;\u91cd\u65b0\u52a0\u8f7d Nginx&#xff1a;<\/p>\n<p>sudo systemctl reload nginx\n <\/li>\n<hr \/>\n<h4>5.\u00a0\u9a8c\u8bc1\u90e8\u7f72<\/h4>\n<li>\n<p>\u5728\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95ee\u4f60\u7684\u57df\u540d\u6216\u670d\u52a1\u5668 IP \u5730\u5740&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<p>http:\/\/example.com<\/p>\n<p>\u6216<\/p>\n<p>http:\/\/192.168.1.100\n <\/li>\n<li>\u5982\u679c\u4e00\u5207\u6b63\u5e38&#xff0c;\u4f60\u5e94\u8be5\u80fd\u591f\u770b\u5230 Vue \u5e94\u7528\u7684\u9996\u9875\u3002<\/li>\n<hr \/>\n<h4>6.\u00a0\u5e38\u89c1\u95ee\u9898\u6392\u67e5<\/h4>\n<ul>\n<li>\n<p>404 \u9519\u8bef&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u68c0\u67e5\u00a0root\u00a0\u8def\u5f84\u662f\u5426\u6b63\u786e\u6307\u5411\u00a0dist\u00a0\u6587\u4ef6\u5939\u3002<\/p>\n<\/li>\n<li>\n<p>\u786e\u4fdd\u00a0try_files\u00a0\u914d\u7f6e\u6b63\u786e\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Vue \u8def\u7531\u4e0d\u751f\u6548&#xff1a;<\/p>\n<ul>\n<li>\u786e\u4fdd\u00a0location \/\u00a0\u4e2d\u6709\u00a0try_files $uri $uri\/ \/index.html;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Nginx \u914d\u7f6e\u6d4b\u8bd5\u5931\u8d25&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528\u00a0sudo nginx -t\u00a0\u68c0\u67e5\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<\/li>\n<li>\n<p>\u67e5\u770b Nginx \u9519\u8bef\u65e5\u5fd7&#xff1a;\/var\/log\/nginx\/error.log\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>\u6dfb\u52a0\u7528\u6237<\/h3>\n<p>python manage.py useradd -u \u7528\u6237\u540d -p \u5bc6\u7801 -n \u6635\u79f0 [-s]<\/p>\n<h3>\u540e\u53f0\u542f\u52a8django\u542f\u52a8\u811a\u672c<\/h3>\n<p>\u4ee5\u5927\u5c4f\u4e3a\u4f8b:<\/p>\n<p>nohup python \/fishing_trace_wsp\/datacenter\/screenbackend\/manage.py runserver 0.0.0.0:8001 &gt;&gt; output.log 2&gt;&gt;output.log &amp;<\/p>\n<p>\u5176\u4e2d &gt;&gt; \u4ee3\u8868\u8ffd\u52a0\u5230\u6587\u4ef6\u672b\u5c3e&#xff0c;output.log\u662f\u8f93\u51fa\u65e5\u5fd7\u6587\u4ef6\u540d&#xff0c;&amp;\u8868\u793a\u4efb\u52a1\u5728\u540e\u53f0\u6267\u884c&#xff0c;\u5373\u4f7fssh\u7a97\u53e3\u5173\u95ed&#xff0c;\u670d\u52a1\u4f9d\u7136\u4f1a\u5728\u540e\u53f0\u6301\u7eed\u8fd0\u884c\u3002<\/p>\n<p>\u5982\u679c\u662fdatacenter<\/p>\n<p>\u5219\u9700\u8981\u5148\u5207\u6362\u5230\u5bf9\u5e94\u865a\u62df\u73af\u5883(datacenter)&#xff0c;\u518d\u8fd0\u884c\u542f\u52a8\u6307\u4ee4<\/p>\n<p>conda activate datacenter<\/p>\n<p>nohup python \/fishing_trace_wsp\/datacenter\/backend\/manage.py runserver 0.0.0.0:8002 &gt;&gt; output.log 2&gt;&gt;output.log &amp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb841\u6b21\uff0c\u70b9\u8d5e17\u6b21\uff0c\u6536\u85cf13\u6b21\u3002\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u5df2\u7ecf\u6210\u529f\u5c06 Vue 2 \u9879\u76ee\u6253\u5305\u5e76\u90e8\u7f72\u5230\u670d\u52a1\u5668\u4e0a\uff0c\u4f7f\u7528 Nginx \u4f5c\u4e3a Web \u670d\u52a1\u5668\u3002\u5982\u679c\u6709\u4efb\u4f55\u95ee\u9898\uff0c\u53ef\u4ee5\u68c0\u67e5 Nginx \u7684\u65e5\u5fd7\u6587\u4ef6\uff08\u901a\u5e38\u4f4d\u4e8e\uff09\u6765\u6392\u67e5\u9519\u8bef\u3002\u914d\u7f6e Nginx \u4ee5\u670d\u52a1 Vue \u5e94\u7528\u7684\u6838\u5fc3\u662f\u901a\u8fc7 Nginx \u5c06\u7528\u6237\u7684\u8bf7\u6c42\u6b63\u786e\u5730\u6307\u5411 Vue \u5e94\u7528\u7684\u9759\u6001\u6587\u4ef6\uff08\u5982index.html\u3001JavaScript\u3001CSS \u7b49\uff09\uff0c\u5e76\u786e\u4fdd Vue \u7684\u8def\u7531\uff08\u5982 Vue Router\uff09\u80fd\u591f\u6b63\u5e38\u5de5\u4f5c\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[90,87,43],"topic":[],"class_list":["post-41137","post","type-post","status-publish","format-standard","hentry","category-server","tag-npm","tag-87","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5982\u4f55\u5c06vue2\u4f7f\u7528npm run build\u6253\u5305\u597d\u7684\u6587\u4ef6\u4e0a\u4f20\u5230\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/41137.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5982\u4f55\u5c06vue2\u4f7f\u7528npm run build\u6253\u5305\u597d\u7684\u6587\u4ef6\u4e0a\u4f20\u5230\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb841\u6b21\uff0c\u70b9\u8d5e17\u6b21\uff0c\u6536\u85cf13\u6b21\u3002\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u5df2\u7ecf\u6210\u529f\u5c06 Vue 2 \u9879\u76ee\u6253\u5305\u5e76\u90e8\u7f72\u5230\u670d\u52a1\u5668\u4e0a\uff0c\u4f7f\u7528 Nginx \u4f5c\u4e3a Web \u670d\u52a1\u5668\u3002\u5982\u679c\u6709\u4efb\u4f55\u95ee\u9898\uff0c\u53ef\u4ee5\u68c0\u67e5 Nginx \u7684\u65e5\u5fd7\u6587\u4ef6\uff08\u901a\u5e38\u4f4d\u4e8e\uff09\u6765\u6392\u67e5\u9519\u8bef\u3002\u914d\u7f6e Nginx \u4ee5\u670d\u52a1 Vue \u5e94\u7528\u7684\u6838\u5fc3\u662f\u901a\u8fc7 Nginx \u5c06\u7528\u6237\u7684\u8bf7\u6c42\u6b63\u786e\u5730\u6307\u5411 Vue \u5e94\u7528\u7684\u9759\u6001\u6587\u4ef6\uff08\u5982index.html\u3001JavaScript\u3001CSS \u7b49\uff09\uff0c\u5e76\u786e\u4fdd Vue \u7684\u8def\u7531\uff08\u5982 Vue Router\uff09\u80fd\u591f\u6b63\u5e38\u5de5\u4f5c\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/41137.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-30T23:10:44+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/41137.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/41137.html\",\"name\":\"\u5982\u4f55\u5c06vue2\u4f7f\u7528npm run build\u6253\u5305\u597d\u7684\u6587\u4ef6\u4e0a\u4f20\u5230\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-30T23:10:44+00:00\",\"dateModified\":\"2025-05-30T23:10:44+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/41137.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/41137.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/41137.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5982\u4f55\u5c06vue2\u4f7f\u7528npm run build\u6253\u5305\u597d\u7684\u6587\u4ef6\u4e0a\u4f20\u5230\u670d\u52a1\u5668\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5982\u4f55\u5c06vue2\u4f7f\u7528npm run build\u6253\u5305\u597d\u7684\u6587\u4ef6\u4e0a\u4f20\u5230\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/41137.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5982\u4f55\u5c06vue2\u4f7f\u7528npm run build\u6253\u5305\u597d\u7684\u6587\u4ef6\u4e0a\u4f20\u5230\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb841\u6b21\uff0c\u70b9\u8d5e17\u6b21\uff0c\u6536\u85cf13\u6b21\u3002\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u5df2\u7ecf\u6210\u529f\u5c06 Vue 2 \u9879\u76ee\u6253\u5305\u5e76\u90e8\u7f72\u5230\u670d\u52a1\u5668\u4e0a\uff0c\u4f7f\u7528 Nginx \u4f5c\u4e3a Web \u670d\u52a1\u5668\u3002\u5982\u679c\u6709\u4efb\u4f55\u95ee\u9898\uff0c\u53ef\u4ee5\u68c0\u67e5 Nginx \u7684\u65e5\u5fd7\u6587\u4ef6\uff08\u901a\u5e38\u4f4d\u4e8e\uff09\u6765\u6392\u67e5\u9519\u8bef\u3002\u914d\u7f6e Nginx \u4ee5\u670d\u52a1 Vue \u5e94\u7528\u7684\u6838\u5fc3\u662f\u901a\u8fc7 Nginx \u5c06\u7528\u6237\u7684\u8bf7\u6c42\u6b63\u786e\u5730\u6307\u5411 Vue \u5e94\u7528\u7684\u9759\u6001\u6587\u4ef6\uff08\u5982index.html\u3001JavaScript\u3001CSS \u7b49\uff09\uff0c\u5e76\u786e\u4fdd Vue \u7684\u8def\u7531\uff08\u5982 Vue Router\uff09\u80fd\u591f\u6b63\u5e38\u5de5\u4f5c\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/41137.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-30T23:10:44+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/41137.html","url":"https:\/\/www.wsisp.com\/helps\/41137.html","name":"\u5982\u4f55\u5c06vue2\u4f7f\u7528npm run build\u6253\u5305\u597d\u7684\u6587\u4ef6\u4e0a\u4f20\u5230\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-30T23:10:44+00:00","dateModified":"2025-05-30T23:10:44+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/41137.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/41137.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/41137.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5982\u4f55\u5c06vue2\u4f7f\u7528npm run build\u6253\u5305\u597d\u7684\u6587\u4ef6\u4e0a\u4f20\u5230\u670d\u52a1\u5668"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/41137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=41137"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/41137\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=41137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=41137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=41137"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=41137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}