-
Notifications
You must be signed in to change notification settings - Fork 90
deploy
Peter Wang edited this page Nov 15, 2017
·
5 revisions
购买阿里云 ECS 服务器,上面安装 ubuntu 14.04(16.04 操作也基本一样)。
# login as root, and create a new user for all the tasks
ssh root@the_ip_of_this_server
adduser peter --ingroup sudo
su peter
cd # go to /home/peter
echo "安装辅助工具"
sudo apt-get -y install git curl tmux
echo "安装 NVM"
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash
echo ”查看最近的 node 版本"
nvm ls-remove
echo "安装最新版 node“
nvm install v9.2.0
echo "现在开始安装 nginx 服务器"
sudo apt-get install -y nginx
到服务器上
echo "安装 mongodb"
sudo apt-get install -y mongodb
echo "export NODE_ENV=production 这样 npm 装包会忽略 devDependency"
export NODE_ENV=production
nginx 配置 api.conf
server {
listen 80;
server_name api.haoqicat.com;
location / {
proxy_pass http://localhost:3008;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_x_forwarded_host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 3m;
proxy_send_timeout 3m;
}
}
每次修改完 nginx 配置要运行
sudo service nginx reload
重新加载一下配置文件。
首先修改 client/src/settings.js 文件,把里面用到的 server-api 的链接都改为 http://api.haoqicat.com
本地进入项目
npm run build
这样项目根目录下的 build/ 文件夹中就是编译输出,配置文件也就会被编译到里面了。
上传到服务器
scp -avr build/* haoqicat.com:sites/haoqicat/
nginx 配置
/etc/nginx/site-enabled/haoqicat.conf
server {
listen 80;
server_name haoqicat.com;
gzip on;
root /home/peter/sites/haoqicat/;
location / {
try_files $uri /index.html;
}
}