{"id":62609,"date":"2025-04-29T09:34:55","date_gmt":"2025-04-29T01:34:55","guid":{"rendered":"https:\/\/fwq.ai\/blog\/62609\/"},"modified":"2025-04-29T09:34:55","modified_gmt":"2025-04-29T01:34:55","slug":"%e6%95%99%e4%bd%a0%e5%a6%82%e4%bd%95%e9%85%8d%e7%bd%aenginx%e3%80%81pm2%e5%92%8cvps%e6%9c%8d%e5%8a%a1%e5%99%a8-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/62609\/","title":{"rendered":"\u6559\u4f60\u5982\u4f55\u914d\u7f6eNGINX\u3001PM2\u548cVPS\u670d\u52a1\u5668"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/164\/169569343460061.jpg\" class=\"aligncenter\" title=\"\u6559\u4f60\u5982\u4f55\u914d\u7f6eNGINX\u3001PM2\u548cVPS\u670d\u52a1\u5668\u63d2\u56fe\" alt=\"\u6559\u4f60\u5982\u4f55\u914d\u7f6eNGINX\u3001PM2\u548cVPS\u670d\u52a1\u5668\u63d2\u56fe\" \/><\/p>\n<p>\u6559\u4f60\u5982\u4f55\u914d\u7f6eNGINX\u3001PM2\u548cVPS\u670d\u52a1\u5668<\/p>\n<p>\u5f15\u8a00\uff1a<br \/>\u5728\u73b0\u4ee3\u7f51\u7ad9\u5f00\u53d1\u4e2d\uff0c\u914d\u7f6e\u4e00\u4e2a\u9ad8\u6548\u7684\u670d\u52a1\u5668\u73af\u5883\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002NGINX\u662f\u4e00\u4e2a\u6d41\u884c\u7684\u9ad8\u6027\u80fdWeb\u670d\u52a1\u5668\uff0c\u800cPM2\u662f\u4e00\u4e2a\u5f3a\u5927\u7684Node.js\u8fdb\u7a0b\u7ba1\u7406\u5de5\u5177\u3002\u672c\u6587\u5c06\u5411\u4f60\u5c55\u793a\u5982\u4f55\u5728VPS\u670d\u52a1\u5668\u4e0a\u914d\u7f6eNGINX\u548cPM2\uff0c\u5e76\u63d0\u4f9b\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p>\u7b2c\u4e00\u90e8\u5206\uff1a\u5b89\u88c5\u548c\u914d\u7f6eNGINX<\/p>\n<p>\u7b2c\u4e00\u6b65\uff1a\u5b89\u88c5NGINX<br \/>\u8981\u4f7f\u7528NGINX\u4f5c\u4e3a\u4f60\u7684Web\u670d\u52a1\u5668\uff0c\u9996\u5148\u9700\u8981\u5728VPS\u670d\u52a1\u5668\u4e0a\u8fdb\u884c\u5b89\u88c5\u3002\u6839\u636e\u4f60\u6240\u4f7f\u7528\u7684\u64cd\u4f5c\u7cfb\u7edf\u7c7b\u578b\uff0c\u9009\u62e9\u9002\u5408\u7684\u5b89\u88c5\u65b9\u6cd5\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662fUbuntu\u64cd\u4f5c\u7cfb\u7edf\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<pre>sudo apt update\nsudo apt install nginx<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u7b2c\u4e8c\u6b65\uff1a\u914d\u7f6eNGINX<br \/>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5f00\u59cb\u914d\u7f6eNGINX\u4ee5\u9002\u5e94\u4f60\u7684\u7f51\u7ad9\u9700\u6c42\u3002<\/p>\n<ol>\n<li>\n<p>\u6253\u5f00NGINX\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre>sudo nano \/etc\/nginx\/nginx.conf<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/li>\n<li>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff0c\u5c06\u8bf7\u6c42\u8f6c\u53d1\u5230PM2\u7ba1\u7406\u7684Node.js\u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n<pre>http {\n  server {\n listen 80;\n server_name your_domain.com;\n\n location \/ {\n   proxy_pass http:\/\/localhost:3000; \/\/ \u5c06\u7aef\u53e3\u53f7\u6539\u4e3a\u4f60\u7684Node.js\u5e94\u7528\u7a0b\u5e8f\u7aef\u53e3\u53f7\n   proxy_http_version 1.1;\n   proxy_set_header Upgrade $http_upgrade;\n   proxy_set_header Connection 'upgrade';\n   proxy_set_header Host $host;\n   proxy_cache_bypass $http_upgrade;\n }\n  }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/li>\n<li>\u4fdd\u5b58\u66f4\u6539\u5e76\u9000\u51fa\u914d\u7f6e\u6587\u4ef6\u3002<\/li>\n<\/ol>\n<p>\u7b2c\u4e09\u6b65\uff1a\u542f\u52a8NGINX<br \/>\u5b8c\u6210\u914d\u7f6e\u540e\uff0c\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8NGINX\uff1a<\/p>\n<pre>sudo service nginx start<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u73b0\u5728\uff0cNGINX\u5df2\u7ecf\u914d\u7f6e\u5e76\u8fd0\u884c\u5728\u4f60\u7684VPS\u670d\u52a1\u5668\u4e0a\u3002<\/p>\n<p>\u7b2c\u4e8c\u90e8\u5206\uff1a\u5b89\u88c5\u548c\u914d\u7f6ePM2<\/p>\n<p>\u7b2c\u4e00\u6b65\uff1a\u5b89\u88c5PM2<br \/>\u8981\u4f7f\u7528PM2\u7ba1\u7406\u4f60\u7684Node.js\u5e94\u7528\u7a0b\u5e8f\uff0c\u9996\u5148\u9700\u8981\u5728VPS\u670d\u52a1\u5668\u4e0a\u5b89\u88c5PM2\u3002<\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<pre>sudo npm install -g pm2<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u7b2c\u4e8c\u6b65\uff1a\u542f\u52a8Node.js\u5e94\u7528\u7a0b\u5e8f<br \/>\u5728\u4f7f\u7528PM2\u7ba1\u7406\u4f60\u7684Node.js\u5e94\u7528\u7a0b\u5e8f\u4e4b\u524d\uff0c\u9700\u8981\u786e\u4fdd\u5e94\u7528\u7a0b\u5e8f\u5df2\u7ecf\u6b63\u786e\u90e8\u7f72\u3002<\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8\u4f60\u7684Node.js\u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n<pre>pm2 start your_app.js \/\/ \u5c06\"your_app.js\"\u66ff\u6362\u4e3a\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u6587\u4ef6\u540d<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u7b2c\u4e09\u6b65\uff1a\u914d\u7f6ePM2\u5f00\u673a\u81ea\u542f\u52a8<br \/>\u4e3a\u4e86\u4fdd\u8bc1Node.js\u5e94\u7528\u7a0b\u5e8f\u5728\u670d\u52a1\u5668\u91cd\u542f\u540e\u81ea\u52a8\u542f\u52a8\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u914d\u7f6ePM2\u5f00\u673a\u81ea\u542f\u52a8\uff1a<\/p>\n<pre>pm2 startup<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd0\u884c\u4ee5\u4e0a\u547d\u4ee4\u540e\uff0c\u5c06\u4f1a\u6536\u5230\u4e00\u6761\u63d0\u793a\u4fe1\u606f\uff0c\u6309\u7167\u63d0\u793a\u4fe1\u606f\u7ee7\u7eed\u64cd\u4f5c\u5373\u53ef\u3002<\/p>\n<p>\u73b0\u5728\uff0cPM2\u5df2\u7ecf\u5b89\u88c5\u5e76\u914d\u7f6e\u5b8c\u6210\u3002<\/p>\n<p>\u7b2c\u4e09\u90e8\u5206\uff1a\u90e8\u7f72\u5230VPS\u670d\u52a1\u5668<\/p>\n<p>\u7b2c\u4e00\u6b65\uff1a\u4e0a\u4f20\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u6587\u4ef6<br \/>\u5c06\u4f60\u7684Node.js\u5e94\u7528\u7a0b\u5e8f\u6587\u4ef6\u4e0a\u4f20\u5230VPS\u670d\u52a1\u5668\uff0c\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528scp\u547d\u4ee4\u5b9e\u73b0\u6587\u4ef6\u4f20\u8f93\uff1a<\/p>\n<pre>scp your_app.js username@your_server_ip:\/path\/to\/your_app.js<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u7b2c\u4e8c\u6b65\uff1a\u8fdb\u5165\u5e94\u7528\u7a0b\u5e8f\u6587\u4ef6\u6240\u5728\u7684\u8def\u5f84<br \/>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u5165\u5230\u5e94\u7528\u7a0b\u5e8f\u6587\u4ef6\u6240\u5728\u7684\u8def\u5f84\uff1a<\/p>\n<pre>cd \/path\/to<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u7b2c\u4e09\u6b65\uff1a\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f<br \/>\u4f7f\u7528PM2\u542f\u52a8\u4f60\u7684Node.js\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>pm2 start your_app.js<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5230\u6b64\u4e3a\u6b62\uff0c\u4f60\u5df2\u7ecf\u6210\u529f\u914d\u7f6e\u4e86NGINX\u3001PM2\u548cVPS\u670d\u52a1\u5668\u3002\u73b0\u5728\u4f60\u7684\u7f51\u7ad9\u5df2\u7ecf\u53ef\u4ee5\u901a\u8fc7\u670d\u52a1\u5668\u7684IP\u5730\u5740\u6216\u8005\u57df\u540d\u6765\u8bbf\u95ee\u4e86\u3002<\/p>\n<p>\u603b\u7ed3\uff1a<br \/>\u672c\u6587\u5411\u4f60\u5c55\u793a\u4e86\u5982\u4f55\u5728VPS\u670d\u52a1\u5668\u4e0a\u914d\u7f6eNGINX\u548cPM2\uff0c\u5e76\u63d0\u4f9b\u4e86\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u3002\u901a\u8fc7\u914d\u7f6eNGINX\u548cPM2\uff0c\u53ef\u4ee5\u63d0\u9ad8\u670d\u52a1\u5668\u7684\u6027\u80fd\u548c\u7ba1\u7406\u80fd\u529b\uff0c\u5b9e\u73b0\u66f4\u597d\u7684\u7f51\u7ad9\u4f53\u9a8c\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff0c\u795d\u4f60\u5728\u670d\u52a1\u5668\u914d\u7f6e\u65b9\u9762\u53d6\u5f97\u6210\u529f\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6559\u4f60\u5982\u4f55\u914d\u7f6eNGINX\u3001PM2\u548cVPS\u670d\u52a1\u5668\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8FDCServers\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6559\u4f60\u5982\u4f55\u914d\u7f6eNGINX\u3001PM2\u548cVPS\u670d\u52a1\u5668 \u5f15\u8a00\uff1a\u5728\u73b0\u4ee3\u7f51\u7ad9\u5f00\u53d1\u4e2d\uff0c\u914d\u7f6e\u4e00\u4e2a\u9ad8\u6548\u7684\u670d\u52a1\u5668\u73af\u5883\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002NGINX\u662f\u4e00\u4e2a\u6d41\u884c\u7684\u9ad8\u6027\u80fdWeb\u670d\u52a1\u5668\uff0c\u800cPM2\u662f\u4e00\u4e2a\u5f3a\u5927\u7684Node.js\u8fdb\u7a0b\u7ba1\u7406\u5de5\u5177\u3002\u672c\u6587\u5c06\u5411\u4f60\u5c55\u793a\u5982\u4f55\u5728VPS\u670d\u52a1\u5668\u4e0a\u914d\u7f6eNGINX\u548cPM2\uff0c\u5e76\u63d0\u4f9b\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u3002 \u7b2c\u4e00\u90e8\u5206\uff1a\u5b89\u88c5\u548c\u914d\u7f6eNGINX \u7b2c\u4e00\u6b65\uff1a\u5b89\u88c5NGINX\u8981\u4f7f\u7528NGINX\u4f5c\u4e3a\u4f60\u7684Web\u670d\u52a1\u5668\uff0c\u9996\u5148\u9700\u8981\u5728VPS\u670d\u52a1\u5668\u4e0a\u8fdb\u884c\u5b89\u88c5\u3002\u6839\u636e\u4f60\u6240\u4f7f\u7528\u7684\u64cd\u4f5c\u7cfb\u7edf\u7c7b\u578b\uff0c\u9009\u62e9\u9002\u5408\u7684\u5b89\u88c5\u65b9\u6cd5\u3002 \u4f8b\u5982\uff0c\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662fUbuntu\u64cd\u4f5c\u7cfb\u7edf\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a sudo apt update sudo apt install nginx \u767b\u5f55\u540e\u590d\u5236 \u7b2c\u4e8c\u6b65\uff1a\u914d\u7f6eNGINX\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5f00\u59cb\u914d\u7f6eNGINX\u4ee5\u9002\u5e94\u4f60\u7684\u7f51\u7ad9\u9700\u6c42\u3002 \u6253\u5f00NGINX\u914d\u7f6e\u6587\u4ef6\uff1a sudo nano \/etc\/nginx\/nginx.conf \u767b\u5f55\u540e\u590d\u5236 \u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff0c\u5c06\u8bf7\u6c42\u8f6c\u53d1\u5230PM2\u7ba1\u7406\u7684Node.js\u5e94\u7528\u7a0b\u5e8f\uff1a http { server { listen 80; server_name your_domain.com; location \/ { proxy_pass http:\/\/localhost:3000; \/\/ \u5c06\u7aef\u53e3\u53f7\u6539\u4e3a\u4f60\u7684Node.js\u5e94\u7528\u7a0b\u5e8f\u7aef\u53e3\u53f7 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection &#8216;upgrade&#8217;; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } } } \u767b\u5f55\u540e\u590d\u5236 \u4fdd\u5b58\u66f4\u6539\u5e76\u9000\u51fa\u914d\u7f6e\u6587\u4ef6\u3002 \u7b2c\u4e09\u6b65\uff1a\u542f\u52a8NGINX\u5b8c\u6210\u914d\u7f6e\u540e\uff0c\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8NGINX\uff1a sudo [&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-62609","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/62609","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=62609"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/62609\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=62609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=62609"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=62609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}