{"id":10008184,"date":"2023-08-28T20:59:53","date_gmt":"2023-08-28T12:59:53","guid":{"rendered":"https:\/\/blog.itmax.cn\/?p=10008184"},"modified":"2023-08-28T20:59:53","modified_gmt":"2023-08-28T12:59:53","slug":"linux-%e9%83%a8%e7%bd%b2-node-js-%e7%8e%af%e5%a2%83","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10008184","title":{"rendered":"Linux \u90e8\u7f72 Node.js \u73af\u5883"},"content":{"rendered":"<h2>Linux \u90e8\u7f72 Node.js \u73af\u5883<\/h2>\n<p>Node.js \u662f\u4e00\u4e2a\u57fa\u4e8e Chrome V8 \u5f15\u64ce\u7684 JavaScript \u8fd0\u884c\u73af\u5883\uff0c\u7528\u6765\u65b9\u4fbf\u5feb\u901f\u5730\u642d\u5efa\u6613\u4e8e\u6269\u5c55\u7684\u7f51\u7edc\u5e94\u7528\u3002\u672c\u6587\u9002\u7528\u670d\u52a1\u5668\u7cfb\u7edf\uff1a<\/p>\n<ul>\n<li>CentOS 7<\/li>\n<li>Alibaba Cloud Linux 2<\/li>\n<li>Alibaba Cloud Linux 3<\/li>\n<\/ul>\n<h3>\u64cd\u4f5c\u6b65\u9aa4<\/h3>\n<h4>1.\u8fdc\u7a0b\u8fde\u63a5 ECS \u5b9e\u4f8b<\/h4>\n<ul>\n<li>ssh \u94fe\u63a5<\/li>\n<li>\u901a\u8fc7 Workbench \u8fdc\u7a0b\u8fde\u63a5<\/li>\n<li>\u901a\u8fc7\u5ba2\u6237\u7aef\u8fde\u63a5<\/li>\n<\/ul>\n<h4>2.\u5b89\u88c5\u5e94\u7528<\/h4>\n<h5>2.1 \u5b89\u88c5 Nginx<\/h5>\n<pre><code>yum -y install nginx\nnginx -v<\/code><\/pre>\n<h5>2.2 \u5b89\u88c5 GIT<\/h5>\n<pre><code class=\"bash\">yum install git -y<\/code><\/pre>\n<p>\u5982\u8981\u5b89\u88c5\u6700\u65b0\u7248\u672c git\uff0c\u8bf7\u53c2\u8003<a target=\"_blank\" href=\"https:\/\/link.segmentfault.com\/?enc=r95USd3uKDY2d8fHlnfefQ%3D%3D.fY5Vj7uHq0KJSITxxL7%2FgjHobmN74RaqkW53TQWxICxa7mmCfUwHlAvuM20DjZYw\" rel=\"noopener noreferrer\">Centos7 \u5b89\u88c5\u6700\u65b0\u7248\u672c git<\/a><\/p>\n<h5>2.3 \u5b89\u88c5 Node.js<\/h5>\n<pre><code class=\"bash\">yum install nodejs -y<\/code><\/pre>\n<pre><code class=\"bash\">yum install npm -y<\/code><\/pre>\n<h4>3.\u547d\u4ee4\u884c\u7f8e\u5316<\/h4>\n<h5>3.1 \u5b89\u88c5 zsh \u548c oh-my-zsh<\/h5>\n<p>\u5b89\u88c5 zsh<\/p>\n<pre><code class=\"bash\">yum install zsh<\/code><\/pre>\n<p>\u5207\u6362\u9ed8\u8ba4 shell<\/p>\n<pre><code class=\"bash\">chsh -s \/bin\/zsh<\/code><\/pre>\n<p>\u5b89\u88c5 oh-my-zsh<\/p>\n<pre><code class=\"bash\">git clone https:\/\/github.com\/robbyrussell\/oh-my-zsh.git ~\/.oh-my-zsh\ncp ~\/.oh-my-zsh\/templates\/zshrc.zsh-template ~\/.zshrc<\/code><\/pre>\n<h5>3.2 \u8bed\u6cd5\u9ad8\u4eae\u8bbe\u7f6e<\/h5>\n<p>\u5b89\u88c5<\/p>\n<pre><code class=\"bash\">git clone https:\/\/github.com\/zsh-users\/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~\/.oh-my-zsh\/custom}\/plugins\/zsh-syntax-highlighting<\/code><\/pre>\n<p>\u914d\u7f6e<\/p>\n<p>\u5728 ~\/.zshrc \u7684 plugins \u4e2d\u52a0\u5165 zsh-syntax-highlighting<\/p>\n<pre><code class=\"txt\"># Which plugins would you like to load?\n# Standard plugins can be found in $ZSH\/plugins\/\n# Custom plugins may be added to $ZSH_CUSTOM\/plugins\/\n# Example format: plugins=(rails git textmate ruby lighthouse)\n# Add wisely, as too many plugins slow down shell startup.\nplugins=(git zsh-syntax-highlighting)<\/code><\/pre>\n<h5>3.3 \u81ea\u52a8\u8865\u5168\u63d2\u4ef6\u8bbe\u7f6e<\/h5>\n<p>\u5b89\u88c5<\/p>\n<pre><code class=\"bash\">git clone https:\/\/github.com\/zsh-users\/zsh-autosuggestions $ZSH_CUSTOM\/plugins\/zsh-autosuggestions<\/code><\/pre>\n<p>\u914d\u7f6e<\/p>\n<p>\u5728 ~\/.zshrc \u7684 plugins \u4e2d\u52a0\u5165 zsh-syntax-highlighting<\/p>\n<pre><code class=\"txt\"># Which plugins would you like to load?\n# Standard plugins can be found in $ZSH\/plugins\/\n# Custom plugins may be added to $ZSH_CUSTOM\/plugins\/\n# Example format: plugins=(rails git textmate ruby lighthouse)\n# Add wisely, as too many plugins slow down shell startup.\nplugins=(git zsh-syntax-highlighting zsh-autosuggestions)<\/code><\/pre>\n<h5>3.4 \u91cd\u542f shell \u9a8c\u8bc1\u914d\u7f6e\u662f\u5426\u751f\u6548<\/h5>\n<p>\u914d\u7f6e\u5b8c\u6210\u540e\u9700\u8981\u91cd\u65b0\u542f\u52a8 shell \u6216\u8005\u65b0\u5f00 shell \u7a97\u53e3\u3002<\/p>\n<h5>4.\u90e8\u7f72 Node.js \u5e94\u7528<\/h5>\n<p>\u6839\u636e\u4e2a\u4eba\u4e60\u60ef\u521b\u5efa\u5e94\u7528\u76ee\u5f55<\/p>\n<pre><code class=\"bash\">cd ~\/home\nmkdir apps\ncd apps<\/code><\/pre>\n<p>\u62c9\u53d6\u9879\u76ee\u4ee3\u7801<\/p>\n<pre><code class=\"bash\">git clone YOUR_APP_GIT<\/code><\/pre>\n<p>\u8fd0\u884c\u9879\u76ee\uff08\u6839\u636e\u9879\u76ee\u5177\u4f53\u60c5\u5f62\u5b89\u88c5\u4f9d\u8d56\u8fd0\u884c\u9879\u76ee\uff09<\/p>\n<pre><code>npm run start<\/code><\/pre>\n<h5>5.Nginx \u914d\u7f6e<\/h5>\n<p>\u7f16\u8f91 nginx \u914d\u7f6e\u6587\u4ef6<\/p>\n<pre><code class=\"bash\">vi \/etc\/nginx\/nginx.conf<\/code><\/pre>\n<p>https \u57df\u540d\u8f6c\u53d1\u914d\u7f6e\u89c4\u5219\uff0c\u4e0d\u9700\u8981\u5f00\u542f https \u534f\u8bae\u5c06 ssl \u914d\u7f6e\u9879\u6ce8\u91ca\u5373\u53ef<\/p>\n<pre><code class=\"conf\">  server {\n    listen 80;\n    listen       443 ssl;\n    server_name  api.example.com;\n    index  index.php index.html index.htm;\n\n    #SSL\u914d\u7f6e\n    #ssl on;\n    ssl_certificate      \/path\/to\/example.com.pem; # \u914d\u7f6e\u8bc1\u4e66\uff0c\u586b\u5199\u8bc1\u4e66\u7edd\u5bf9\u8def\u5f84\n    ssl_certificate_key  \/path\/to\/example.com.key; # \u914d\u7f6e\u8bc1\u4e66\u79c1\u94a5\uff0c\u586b\u5199\u8bc1\u4e66\u7edd\u5bf9\u8def\u5f84\n    ssl_session_cache shared:SSL:1m;\n    ssl_session_timeout  10m;\n    ssl_ciphers HIGH:!aNULL:!MD5;\n    ssl_prefer_server_ciphers on;\n\n    location \/ {\n      proxy_pass  http:\/\/127.0.0.1:3000; # \u8f6c\u53d1\u89c4\u5219\uff0c\u8f6c\u53d1\u5230Node\u5e94\u7528\uff0c\u670d\u52a1\u5668\u9700\u8981\u5f00\u542f\u5bf9\u5e94\u7684\u7aef\u53e3\u53f7\n      proxy_set_header Host $proxy_host;\n      proxy_set_header X-Real-IP $remote_addr;\n      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n    }\n  }<\/code><\/pre>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000044158127\">https:\/\/segmentfault.com\/a\/1190000044158127<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux \u90e8\u7f72 Node.js \u73af\u5883 Node.js \u662f\u4e00\u4e2a\u57fa\u4e8e Chrome V8 \u5f15\u64ce\u7684 JavaScr [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10008184","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10008184"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008184\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10008184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10008184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10008184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}