First test on-line:
- On the dev branch project
$ npm run build
- Dev branch in the global project to install http-sever
$ npm i http-server -g
- Start http-sever
$ http-server -c10 //后面的c-10是缓存,可以写,也可以不写
If you find here will not start, and went in to find index.js project file in the config directory, will host configured as 0.0.0.0
- Revised again npm run build (third section can be edited directly in the establishment of the project)
- Enter dist directory
- Start http-server -c10 server
Formally launched steps:
One: Create a remote on-line branch
The first:
- Create the remote on-line for a branch (may also be used to create a local branch pushed to a remote repository)
- If you are using a remote branch created on-line, it creates a local branch of the same, in association with the code on the line to push the remote branch line
The second:
- The simplest way is to create an on-line directly in the local branch, the branch will be based on project dev line of code push to a remote repository
II: buy server (if purchased and configuration skip)
- Optional purchase (Tencent cloud, Ali goes ,,, etc.)
- First configure security group after the purchase is successful, (the more -> Security Group -> Configure security group)
set up inbound rule 0.0.0.0 (default is all ip addresses can access the server [Ali cloud server is not the default configuration for this options, Tencent cloud is configured by default])
If Ali is the cloud server is more -> configure security groups -> configuration rules -> quickly create rules -> configure the following, where the priority must not conflict with other configurations .
- Password - - reboot the server
Tencent cloud password:
Ali cloud password:
- The first login - - use your browser to log - - will enter the server command line,
type ls to see this time will let you enter a password, this password is the password you set the third step.
Note: When you enter a password will not have any display, enter the correct login that is successful, the input error is returned.
The following command line will be displayed after a successful login
cd / root directory view - The second login server approach (common): just find a directory using the command line
$ ssh 服务器用户名@服务器公网IP地址
- Enter the password to access the server's user directory
- Installed in the user directory and git nodejs
$ curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash - //安装更高版本的node
$ yum install nodejs
$ yum install git
If not npm openssl version is low, you need to upgrade
$ yum update openssl -y
- To test whether the server can be accessed
$ cd / 进入服务器根目录
$ cd data 进入data目录(一般都在这个目录创建一个文件夹放项目)
$ mkdir www 创建文件夹(创建一个www的目录用来存放上线的项目)
$ mkdir test 创建上线的项目存放文件夹(名字自行起)
$ cd test 进入该文件夹
$
$//安装以下文件也可在用户目录下直接一次性安装完成
$ npm install -g http-server
$ npm install pm2 -g
$ npm install -g cnpm
$
$//启动方式:
$ http-server -c10 启动服务器
$//也可以用:
$ pm2 start http-server 启动服务器
$ pm2 stop id 就能停止服务器对该id的响应
$ pm2 delete id 从服务器上删除该id
- Deployment Project
$ cd data/www/ 进入www目录
$ git clone -b 远程仓库的上线分支名(远程仓库ssh或https地址) 文件夹的名字 (克隆远程仓库要上线的分支)
$进入这个项目的文件夹 cnpm i 安装项目依赖
$ npm run build
$ cd dist/ 进入dist目录
$ pm2 start http-server 启动服务器
centOS nginx deployment
$ yum install nginx -y
Once installed, it will in the / etc / nginx catalog and saw a pile of papers, which nginx.conf this file is the default nginx configuration files, following a directory called conf.d write our own configuration is placed under this directory.
If the error is:
$ nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)
Then try to perform:
$ nginx -t
$//将得到如下的输出:
$ nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
$ nginx: configuration file /etc/nginx/nginx.conf test is successful
$//再执行:
$ nginx -c /etc/nginx/nginx.conf
$ nginx -s reload
At this time direct access to your public ip address, should be able to see the page displayed is welcome to nginx
/Etc/nginx/conf.d into a new .conf write any name server configuration on the inside
If you do not use the hash router, then then you will refresh the page inaccessible
Only you need to add the server configuration in
location / {
try_files $uri $uri/ /index.html;
}
https://router.vuejs.org/zh/guide/essentials/history-mode.html#%E5%90%8E%E7%AB%AF%E9%85%8D%E7%BD%AE%E4%BE%8B%E5%AD%90
Can not solve the problem of npm run build
$ sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
$ sudo /sbin/mkswap /var/swap.1
$ sudo /sbin/swapon /var/swap.1
//继续npm run build