{"id":62708,"date":"2025-04-29T09:45:03","date_gmt":"2025-04-29T01:45:03","guid":{"rendered":"https:\/\/fwq.ai\/blog\/62708\/"},"modified":"2025-04-29T09:45:03","modified_gmt":"2025-04-29T01:45:03","slug":"nginx-pm2-vps-%e6%9e%84%e5%bb%ba%e9%ab%98%e6%80%a7%e8%83%bd%e7%9a%84web%e6%9c%8d%e5%8a%a1%e5%99%a8-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/62708\/","title":{"rendered":"NGINX PM2 VPS: \u6784\u5efa\u9ad8\u6027\u80fd\u7684Web\u670d\u52a1\u5668"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/465\/014\/169594835981550.jpg\" class=\"aligncenter\" title=\"NGINX PM2 VPS: \u6784\u5efa\u9ad8\u6027\u80fd\u7684Web\u670d\u52a1\u5668\u63d2\u56fe\" alt=\"NGINX PM2 VPS: \u6784\u5efa\u9ad8\u6027\u80fd\u7684Web\u670d\u52a1\u5668\u63d2\u56fe\" \/><\/p>\n<p>NGINX PM2 VPS: \u6784\u5efa\u9ad8\u6027\u80fd\u7684Web\u670d\u52a1\u5668<\/p>\n<p>\u8fd1\u5e74\u6765\uff0c\u968f\u7740\u4e92\u8054\u7f51\u7684\u53d1\u5c55\uff0cWeb\u670d\u52a1\u5668\u7684\u6027\u80fd\u8981\u6c42\u8d8a\u6765\u8d8a\u9ad8\u3002\u4e3a\u4e86\u6ee1\u8db3\u8fd9\u4e9b\u9700\u6c42\uff0c\u5f00\u53d1\u4eba\u5458\u4e0d\u65ad\u63a2\u7d22\u65b0\u7684\u6280\u672f\u548c\u5de5\u5177\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528NGINX\u3001PM2\u548cVPS\u6784\u5efa\u9ad8\u6027\u80fd\u7684Web\u670d\u52a1\u5668\uff0c\u5e76\u9644\u4e0a\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<ol>\n<li>NGINX<br \/>NGINX\u662f\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684Web\u670d\u52a1\u5668\u548c\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\u3002\u5b83\u7684\u8bbe\u8ba1\u76ee\u6807\u662f\u4e3a\u4e86\u5904\u7406\u5927\u91cf\u5e76\u53d1\u8fde\u63a5\uff0c\u5e76\u4e14\u5177\u6709\u51fa\u8272\u7684\u6027\u80fd\u3002\u76f8\u6bd4\u4e8e\u4f20\u7edf\u7684Apache\u670d\u52a1\u5668\uff0cNGINX\u66f4\u52a0\u8f7b\u91cf\u7ea7\uff0c\u5e76\u4e14\u80fd\u591f\u5904\u7406\u66f4\u591a\u7684\u5e76\u53d1\u8bf7\u6c42\u3002<\/li>\n<\/ol>\n<p>\u5728\u5b89\u88c5NGINX\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u786e\u4fddVPS\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86Node.js\u548cnpm\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\uff1a<\/p>\n<pre>sudo apt update\nsudo apt install nodejs\nsudo apt install npm<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5b89\u88c5\u5b8cNode.js\u548cnpm\u4e4b\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528npm\u6765\u5b89\u88c5PM2\uff0c\u8fd9\u662f\u4e00\u4e2a\u7528\u4e8e\u7ba1\u7406Node.js\u5e94\u7528\u7a0b\u5e8f\u7684\u8fdb\u7a0b\u7ba1\u7406\u5668\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<pre>sudo npm install pm2 -g<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>PM2<br \/>PM2\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u7ba1\u7406\u548c\u76d1\u63a7Node.js\u5e94\u7528\u7a0b\u5e8f\u3002\u5b83\u53ef\u4ee5\u81ea\u52a8\u91cd\u65b0\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\uff0c\u786e\u4fdd\u5e94\u7528\u7a0b\u5e8f\u5728\u5d29\u6e83\u65f6\u80fd\u591f\u7ee7\u7eed\u8fd0\u884c\u3002\u6b64\u5916\uff0cPM2\u8fd8\u63d0\u4f9b\u4e86\u65e5\u5fd7\u8bb0\u5f55\u548c\u8fdb\u7a0b\u76d1\u63a7\u7b49\u529f\u80fd\u3002<\/li>\n<\/ol>\n<p>\u5047\u8bbe\u6211\u4eec\u5df2\u7ecf\u6709\u4e00\u4e2aNode.js\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u4e14\u8be5\u5e94\u7528\u7a0b\u5e8f\u7684\u5165\u53e3\u6587\u4ef6\u4e3aapp.js\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f7f\u7528PM2\u8fd0\u884c\u8be5\u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n<pre>pm2 start app.js<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u901a\u8fc7\u8fd0\u884c\u4e0a\u8ff0\u547d\u4ee4\uff0c\u6211\u4eec\u53ef\u4ee5\u786e\u4fddNode.js\u5e94\u7528\u7a0b\u5e8f\u5728\u670d\u52a1\u5668\u542f\u52a8\u540e\u81ea\u52a8\u8fd0\u884c\uff0c\u5e76\u4e14\u5177\u5907\u81ea\u52a8\u91cd\u542f\u7684\u529f\u80fd\u3002<\/p>\n<ol>\n<li>\n<p>NGINX\u914d\u7f6e\u53cd\u5411\u4ee3\u7406<br \/>\u4e3a\u4e86\u5c06\u6240\u6709\u7684\u8bf7\u6c42\u8f6c\u53d1\u7ed9Node.js\u5e94\u7528\u7a0b\u5e8f\uff0c\u6211\u4eec\u9700\u8981\u5728NGINX\u914d\u7f6e\u4e2d\u6dfb\u52a0\u53cd\u5411\u4ee3\u7406\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u7f16\u8f91NGINX\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u7f16\u8f91\uff1a<\/p>\n<pre>sudo nano \/etc\/nginx\/nginx.conf<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/li>\n<\/ol>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\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;\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   <\/p>\n<p>\u5728\u4e0a\u8ff0\u914d\u7f6e\u4e2d\uff0c\u6211\u4eec\u5c06\u6240\u6709\u7684\u8bf7\u6c42\u90fd\u8f6c\u53d1\u7ed9\u672c\u5730\u76843000\u7aef\u53e3\uff0c\u4e5f\u5c31\u662f\u6211\u4eecNode.js\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u7684\u7aef\u53e3\u3002<\/p>\n<p>\u5b8c\u6210\u914d\u7f6e\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u91cd\u542fNGINX\uff1a<\/p>\n<pre>sudo service nginx restart<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u73b0\u5728\uff0c\u6211\u4eec\u5df2\u7ecf\u6210\u529f\u5730\u5c06NGINX\u914d\u7f6e\u4e3a\u53cd\u5411\u4ee3\u7406\uff0c\u5e76\u4e14\u53ef\u4ee5\u4f7f\u7528PM2\u6765\u7ba1\u7406\u6211\u4eec\u7684Node.js\u5e94\u7528\u7a0b\u5e8f\u4e86\u3002<\/p>\n<p>\u603b\u7ed3<br \/>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528NGINX\u3001PM2\u548cVPS\u6765\u6784\u5efa\u9ad8\u6027\u80fd\u7684Web\u670d\u52a1\u5668\u3002\u901a\u8fc7\u4f7f\u7528NGINX\u4f5c\u4e3a\u53cd\u5411\u4ee3\u7406\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u7ba1\u7406\u5e76\u53d1\u8fde\u63a5\uff0c\u5e76\u63d0\u4f9b\u66f4\u597d\u7684\u6027\u80fd\u3002\u53e6\u5916\uff0c\u901a\u8fc7\u4f7f\u7528PM2\u53ef\u4ee5\u786e\u4fdd\u6211\u4eec\u7684Node.js\u5e94\u7528\u7a0b\u5e8f\u5728\u670d\u52a1\u5668\u5d29\u6e83\u540e\u80fd\u591f\u81ea\u52a8\u6062\u590d\u3002<\/p>\n<p>\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff0c\u5e76\u80fd\u591f\u5e2e\u52a9\u4f60\u6784\u5efa\u51fa\u9ad8\u6027\u80fd\u7684Web\u670d\u52a1\u5668\u3002\u5982\u679c\u4f60\u5bf9\u4ee3\u7801\u793a\u4f8b\u6709\u4efb\u4f55\u95ee\u9898\u6216\u9700\u8981\u66f4\u591a\u7684\u6307\u5bfc\uff0c\u8bf7\u968f\u65f6\u5728\u8bc4\u8bba\u533a\u63d0\u95ee\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fNGINX PM2 VPS: \u6784\u5efa\u9ad8\u6027\u80fd\u7684Web\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>NGINX PM2 VPS: \u6784\u5efa\u9ad8\u6027\u80fd\u7684Web\u670d\u52a1\u5668 \u8fd1\u5e74\u6765\uff0c\u968f\u7740\u4e92\u8054\u7f51\u7684\u53d1\u5c55\uff0cWeb\u670d\u52a1\u5668\u7684\u6027\u80fd\u8981\u6c42\u8d8a\u6765\u8d8a\u9ad8\u3002\u4e3a\u4e86\u6ee1\u8db3\u8fd9\u4e9b\u9700\u6c42\uff0c\u5f00\u53d1\u4eba\u5458\u4e0d\u65ad\u63a2\u7d22\u65b0\u7684\u6280\u672f\u548c\u5de5\u5177\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528NGINX\u3001PM2\u548cVPS\u6784\u5efa\u9ad8\u6027\u80fd\u7684Web\u670d\u52a1\u5668\uff0c\u5e76\u9644\u4e0a\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u3002 NGINXNGINX\u662f\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684Web\u670d\u52a1\u5668\u548c\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\u3002\u5b83\u7684\u8bbe\u8ba1\u76ee\u6807\u662f\u4e3a\u4e86\u5904\u7406\u5927\u91cf\u5e76\u53d1\u8fde\u63a5\uff0c\u5e76\u4e14\u5177\u6709\u51fa\u8272\u7684\u6027\u80fd\u3002\u76f8\u6bd4\u4e8e\u4f20\u7edf\u7684Apache\u670d\u52a1\u5668\uff0cNGINX\u66f4\u52a0\u8f7b\u91cf\u7ea7\uff0c\u5e76\u4e14\u80fd\u591f\u5904\u7406\u66f4\u591a\u7684\u5e76\u53d1\u8bf7\u6c42\u3002 \u5728\u5b89\u88c5NGINX\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u786e\u4fddVPS\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86Node.js\u548cnpm\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\uff1a sudo apt update sudo apt install nodejs sudo apt install npm \u767b\u5f55\u540e\u590d\u5236 \u5b89\u88c5\u5b8cNode.js\u548cnpm\u4e4b\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528npm\u6765\u5b89\u88c5PM2\uff0c\u8fd9\u662f\u4e00\u4e2a\u7528\u4e8e\u7ba1\u7406Node.js\u5e94\u7528\u7a0b\u5e8f\u7684\u8fdb\u7a0b\u7ba1\u7406\u5668\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u8fdb\u884c\u5b89\u88c5\uff1a sudo npm install pm2 -g \u767b\u5f55\u540e\u590d\u5236 PM2PM2\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u7ba1\u7406\u548c\u76d1\u63a7Node.js\u5e94\u7528\u7a0b\u5e8f\u3002\u5b83\u53ef\u4ee5\u81ea\u52a8\u91cd\u65b0\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\uff0c\u786e\u4fdd\u5e94\u7528\u7a0b\u5e8f\u5728\u5d29\u6e83\u65f6\u80fd\u591f\u7ee7\u7eed\u8fd0\u884c\u3002\u6b64\u5916\uff0cPM2\u8fd8\u63d0\u4f9b\u4e86\u65e5\u5fd7\u8bb0\u5f55\u548c\u8fdb\u7a0b\u76d1\u63a7\u7b49\u529f\u80fd\u3002 \u5047\u8bbe\u6211\u4eec\u5df2\u7ecf\u6709\u4e00\u4e2aNode.js\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u4e14\u8be5\u5e94\u7528\u7a0b\u5e8f\u7684\u5165\u53e3\u6587\u4ef6\u4e3aapp.js\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f7f\u7528PM2\u8fd0\u884c\u8be5\u5e94\u7528\u7a0b\u5e8f\uff1a pm2 start app.js \u767b\u5f55\u540e\u590d\u5236 \u901a\u8fc7\u8fd0\u884c\u4e0a\u8ff0\u547d\u4ee4\uff0c\u6211\u4eec\u53ef\u4ee5\u786e\u4fddNode.js\u5e94\u7528\u7a0b\u5e8f\u5728\u670d\u52a1\u5668\u542f\u52a8\u540e\u81ea\u52a8\u8fd0\u884c\uff0c\u5e76\u4e14\u5177\u5907\u81ea\u52a8\u91cd\u542f\u7684\u529f\u80fd\u3002 NGINX\u914d\u7f6e\u53cd\u5411\u4ee3\u7406\u4e3a\u4e86\u5c06\u6240\u6709\u7684\u8bf7\u6c42\u8f6c\u53d1\u7ed9Node.js\u5e94\u7528\u7a0b\u5e8f\uff0c\u6211\u4eec\u9700\u8981\u5728NGINX\u914d\u7f6e\u4e2d\u6dfb\u52a0\u53cd\u5411\u4ee3\u7406\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u7f16\u8f91NGINX\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u7f16\u8f91\uff1a sudo nano \/etc\/nginx\/nginx.conf \u767b\u5f55\u540e\u590d\u5236 \u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a http { server { listen 80; server_name your_domain.com; location \/ { proxy_pass http:\/\/localhost:3000; proxy_http_version 1.1; proxy_set_header [&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-62708","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/62708","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=62708"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/62708\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=62708"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=62708"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=62708"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}