前提:安装了PM2插件、安装了nginx,域名已绑定,网站目录已创建。
1、将文件原封不动传到网站根目录(node_modules不用上传),这里是先打包为zip,传到服务器进行解压缩的:


2、进入终端面板,运行npm install安装依赖:

3、进入文件面板,找到找到/config/config.prod.js,查看下端口号,或者更改端口号,后面代理要用到:

4、进入网站面板,找到当前网站,点击设置,进入网站设置面板,找到配置文件,加入下面的代码:
location / { proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_pass http://127.0.0.1:8081/; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 0d; error_log /dev/null; access_log /dev/null; proxy_pass http://127.0.0.1:8081; } location ~ .*\.(js|css)?$ { expires 0h; error_log /dev/null; access_log /dev/null; proxy_pass http://127.0.0.1:8081; }注意,端口号要和第三步的端口号保持一致,expires后的0h表示不使用缓存,否则会导致重新修改不能及时生效。截图如下:

5、进入终端面板,运行npm start:

这里要说明下:
①、在本地调试用npm dev,在线上要用npm start,npm dev要始终将终端开启,而npm start运行后,可以将终端关闭。
②、如果要停止,请用npm stop
③、所有的终端命令,都要cd到当前项目放置的位置运行。
④、如果要修改,需要先npm stop,将修改的文件上传覆盖,再npm start。