{"id":32512,"date":"2022-08-23T18:41:02","date_gmt":"2023-11-10T05:05:25","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ec2%e4%b8%8a%e8%bf%90%e8%a1%8cnode-js-nginx-pm2-express4%e7%9a%84node%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/"},"modified":"2024-01-15T07:20:52","modified_gmt":"2024-01-14T23:20:52","slug":"%e5%9c%a8ec2%e4%b8%8a%e8%bf%90%e8%a1%8cnode-js-nginx-pm2-express4%e7%9a%84node%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ec2%e4%b8%8a%e8%bf%90%e8%a1%8cnode-js-nginx-pm2-express4%e7%9a%84node%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/","title":{"rendered":"\u5728EC2\u4e0a\u8fd0\u884cnode.js + nginx + pm2 + express4\u7684node\u5e94\u7528\u7a0b\u5e8f"},"content":{"rendered":"<h2>EC2 \u4e0a\u7684 node.js \u670d\u52a1\u5668.<\/h2>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u8981\u51c6\u5907\u597dnode.js\u7684\u73af\u5883\u3002<br \/>\n\u672c\u6b21\u4f7f\u7528\u7684\u7248\u672c\u662fv0.10.36\u3002<br \/>\n\u6211\u4eec\u5c06\u4f7f\u7528git\u8fdc\u7a0b\u4ed3\u5e93\u4e2d\u5b58\u653e\u7684node.js\u4ee3\u7801\u3002<\/p>\n<pre class=\"post-pre\"><code>$ sudo yum update -y\r\n$ sudo yum install git gcc-c++ make openssl-devel -y\r\n$ git clone git:\/\/github.com\/creationix\/nvm.git .nvm\r\n$ source ~\/.nvm\/nvm.sh\r\n$ nvm install v0.10.36\r\n$ nvm alias default v0.10.36\r\n$ vim ~\/.bash_profile\r\nif [[ -f ~\/.nvm\/nvm.sh ]]; then\r\n  source ~\/.nvm\/nvm.sh\r\n    _nodejs_use_version=\"v0.10.36\"\r\n    if nvm ls | grep -F -e \"${_nodejs_use_version}\" &gt;\/dev\/null 2&gt;&amp;1 ;then\r\n      nvm use \"${_nodejs_use_version}\" &gt;\/dev\/null\r\n      export NODE_PATH=${NVM_PATH}_modules${NODE_PATH:+:}${NODE_PATH}\r\n    fi\r\n    unset _nodejs_use_version\r\nfi\r\n<\/code><\/pre>\n<h4>\u5b89\u88c5nginx<\/h4>\n<pre class=\"post-pre\"><code>$ sudo yum install nginx -y\r\n$ nginx -v\r\n$ sudo chkconfig nginx on\r\n$ sudo service nginx start\r\n$ sudo vim \/etc\/nginx\/conf.d\/node-app.conf\r\nupstream node-app {\r\n    server localhost:3000;\r\n}\r\n\r\nserver {\r\n    listen       80;\r\n    server_name  10.211.55.2;\r\n    proxy_redirect                          off;\r\n    proxy_set_header Host                   $host;\r\n    proxy_set_header X-Real-IP              $remote_addr;\r\n    proxy_set_header X-Forwarded-Host       $host;\r\n    proxy_set_header X-Forwarded-Server     $host;\r\n    proxy_set_header X-Forwarded-For        $proxy_add_x_forwarded_for;\r\n    location \/ {\r\n        proxy_pass http:\/\/node-app\/;\r\n    }\r\n    error_page   500 502 503 504  \/50x.html;\r\n    location = \/50x.html {  \r\n    root   \/usr\/share\/nginx\/html;\r\n    }\r\n}\r\n\r\n$ sudo service nginx restart\r\n<\/code><\/pre>\n<h4>\u5e94\u7528\u7a0b\u5e8f\u8bbe\u7f6e<\/h4>\n<pre class=\"post-pre\"><code>$ git pull origin master nodeapp\r\n$ cd nodeapp\r\n$ npm install\r\n<\/code><\/pre>\n<h4>\u8282\u70b9\u5b88\u62a4\u8fdb\u7a0b\u4f7f\u7528pm2<\/h4>\n<p>\u4ee5\u4e0b\u662f\u5c06node\u5e94\u7528\u7a0b\u5e8f\u8bbe\u7f6e\u4e3a\u5b88\u62a4\u7a0b\u5e8f\u7684\u6700\u540e\u914d\u7f6e\u3002<br \/>\n\u7531\u4e8e\u672c\u6b21\u4f7f\u7528\u7684\u662fexpress4\uff0c\u6240\u4ee5\u8981\u5c06\u5176\u4f5c\u4e3a\u670d\u52a1\u5668\u542f\u52a8\uff0c\u9700\u8981\u5c06\u5176\u8bbe\u4e3a.\/bin\/www.js\u3002\uff08\u539f\u672c\u5e94\u8be5\u662f.\/bin\/www\u6587\u4ef6\uff0c\u6240\u4ee5\u8bf7\u590d\u5236\u4e00\u4efd\u3002\uff09<\/p>\n<pre class=\"post-pre\"><code>$ npm install -g pm2\r\n$ pm2 start .\/bin\/www.js -i max\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>EC2 \u4e0a\u7684 node.js \u670d\u52a1\u5668. \u9996\u5148\uff0c\u6211\u4eec\u8981\u51c6\u5907\u597dnode.js\u7684\u73af\u5883\u3002 \u672c\u6b21\u4f7f\u7528\u7684\u7248\u672c\u662fv0.10. [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-32512","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5728EC2\u4e0a\u8fd0\u884cnode.js + nginx + pm2 + express4\u7684node\u5e94\u7528\u7a0b\u5e8f - Blog - Silicon Cloud<\/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.silicloud.com\/zh\/blog\/\u5728ec2\u4e0a\u8fd0\u884cnode-js-nginx-pm2-express4\u7684node\u5e94\u7528\u7a0b\u5e8f\u3002\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5728EC2\u4e0a\u8fd0\u884cnode.js + nginx + pm2 + express4\u7684node\u5e94\u7528\u7a0b\u5e8f\" \/>\n<meta property=\"og:description\" content=\"EC2 \u4e0a\u7684 node.js \u670d\u52a1\u5668. \u9996\u5148\uff0c\u6211\u4eec\u8981\u51c6\u5907\u597dnode.js\u7684\u73af\u5883\u3002 \u672c\u6b21\u4f7f\u7528\u7684\u7248\u672c\u662fv0.10. [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u5728ec2\u4e0a\u8fd0\u884cnode-js-nginx-pm2-express4\u7684node\u5e94\u7528\u7a0b\u5e8f\u3002\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-10T05:05:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-14T23:20:52+00:00\" \/>\n<meta name=\"author\" content=\"\u97f5, \u79d1\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u97f5, \u79d1\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ec2%e4%b8%8a%e8%bf%90%e8%a1%8cnode-js-nginx-pm2-express4%e7%9a%84node%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ec2%e4%b8%8a%e8%bf%90%e8%a1%8cnode-js-nginx-pm2-express4%e7%9a%84node%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/\",\"name\":\"\u5728EC2\u4e0a\u8fd0\u884cnode.js + nginx + pm2 + express4\u7684node\u5e94\u7528\u7a0b\u5e8f - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-11-10T05:05:25+00:00\",\"dateModified\":\"2024-01-14T23:20:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ec2%e4%b8%8a%e8%bf%90%e8%a1%8cnode-js-nginx-pm2-express4%e7%9a%84node%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ec2%e4%b8%8a%e8%bf%90%e8%a1%8cnode-js-nginx-pm2-express4%e7%9a%84node%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ec2%e4%b8%8a%e8%bf%90%e8%a1%8cnode-js-nginx-pm2-express4%e7%9a%84node%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5728EC2\u4e0a\u8fd0\u884cnode.js + nginx + pm2 + express4\u7684node\u5e94\u7528\u7a0b\u5e8f\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e\",\"name\":\"\u97f5, \u79d1\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g\",\"caption\":\"\u97f5, \u79d1\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/yunke\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ec2%e4%b8%8a%e8%bf%90%e8%a1%8cnode-js-nginx-pm2-express4%e7%9a%84node%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u5728EC2\u4e0a\u8fd0\u884cnode.js + nginx + pm2 + express4\u7684node\u5e94\u7528\u7a0b\u5e8f - Blog - Silicon Cloud","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.silicloud.com\/zh\/blog\/\u5728ec2\u4e0a\u8fd0\u884cnode-js-nginx-pm2-express4\u7684node\u5e94\u7528\u7a0b\u5e8f\u3002\/","og_locale":"zh_CN","og_type":"article","og_title":"\u5728EC2\u4e0a\u8fd0\u884cnode.js + nginx + pm2 + express4\u7684node\u5e94\u7528\u7a0b\u5e8f","og_description":"EC2 \u4e0a\u7684 node.js \u670d\u52a1\u5668. \u9996\u5148\uff0c\u6211\u4eec\u8981\u51c6\u5907\u597dnode.js\u7684\u73af\u5883\u3002 \u672c\u6b21\u4f7f\u7528\u7684\u7248\u672c\u662fv0.10. [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u5728ec2\u4e0a\u8fd0\u884cnode-js-nginx-pm2-express4\u7684node\u5e94\u7528\u7a0b\u5e8f\u3002\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-11-10T05:05:25+00:00","article_modified_time":"2024-01-14T23:20:52+00:00","author":"\u97f5, \u79d1","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u97f5, \u79d1","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ec2%e4%b8%8a%e8%bf%90%e8%a1%8cnode-js-nginx-pm2-express4%e7%9a%84node%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ec2%e4%b8%8a%e8%bf%90%e8%a1%8cnode-js-nginx-pm2-express4%e7%9a%84node%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/","name":"\u5728EC2\u4e0a\u8fd0\u884cnode.js + nginx + pm2 + express4\u7684node\u5e94\u7528\u7a0b\u5e8f - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-11-10T05:05:25+00:00","dateModified":"2024-01-14T23:20:52+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ec2%e4%b8%8a%e8%bf%90%e8%a1%8cnode-js-nginx-pm2-express4%e7%9a%84node%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ec2%e4%b8%8a%e8%bf%90%e8%a1%8cnode-js-nginx-pm2-express4%e7%9a%84node%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ec2%e4%b8%8a%e8%bf%90%e8%a1%8cnode-js-nginx-pm2-express4%e7%9a%84node%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u5728EC2\u4e0a\u8fd0\u884cnode.js + nginx + pm2 + express4\u7684node\u5e94\u7528\u7a0b\u5e8f"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e","name":"\u97f5, \u79d1","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g","caption":"\u97f5, \u79d1"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/yunke\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ec2%e4%b8%8a%e8%bf%90%e8%a1%8cnode-js-nginx-pm2-express4%e7%9a%84node%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/32512","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=32512"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/32512\/revisions"}],"predecessor-version":[{"id":57316,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/32512\/revisions\/57316"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=32512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=32512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=32512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}