共计 2143 个字符,预计需要花费 6 分钟才能阅读完成。
Linux 部署 Node.js 环境
Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境,用来不便疾速地搭建易于扩大的网络应用。本文实用服务器零碎:
- CentOS 7
- Alibaba Cloud Linux 2
- Alibaba Cloud Linux 3
操作步骤
1. 近程连贯 ECS 实例
- ssh 链接
- 通过 Workbench 近程连贯
- 通过客户端连贯
2. 装置利用
2.1 装置 Nginx
yum -y install nginx
nginx -v
2.2 装置 GIT
yum install git -y
如要装置最新版本 git,请参考 Centos7 装置最新版本 git
2.3 装置 Node.js
yum install nodejs -y
yum install npm -y
3. 命令行丑化
3.1 装置 zsh 和 oh-my-zsh
装置 zsh
yum install zsh
切换默认 shell
chsh -s /bin/zsh
装置 oh-my-zsh
git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
3.2 语法高亮设置
装置
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
配置
在 ~/.zshrc 的 plugins 中退出 zsh-syntax-highlighting
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git zsh-syntax-highlighting)
3.3 主动补全插件设置
装置
git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
配置
在 ~/.zshrc 的 plugins 中退出 zsh-syntax-highlighting
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git zsh-syntax-highlighting zsh-autosuggestions)
3.4 重启 shell 验证配置是否失效
配置实现后须要重新启动 shell 或者新开 shell 窗口。
4. 部署 Node.js 利用
依据集体习惯创立利用目录
cd ~/home
mkdir apps
cd apps
拉取我的项目代码
git clone YOUR_APP_GIT
运行我的项目(依据我的项目具体情景装置依赖运行我的项目)
npm run start
5.Nginx 配置
编辑 nginx 配置文件
vi /etc/nginx/nginx.conf
https 域名转发配置规定,不须要开启 https 协定将 ssl 配置项正文即可
server {
listen 80;
listen 443 ssl;
server_name api.example.com;
index index.php index.html index.htm;
#SSL 配置
#ssl on;
ssl_certificate /path/to/example.com.pem; # 配置证书,填写证书绝对路径
ssl_certificate_key /path/to/example.com.key; # 配置证书私钥,填写证书绝对路径
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://127.0.0.1:3000; # 转发规定,转发到 Node 利用,服务器须要开启对应的端口号
proxy_set_header Host $proxy_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
正文完