前提: 先要运行 mysql 数据库才能将 服务器正常启动
<br />
打开文件夹(wqx-shop-serve) 将vue项目打包后的 dist文件夹复制到文件中, 并且再 创建 app.js 文件
image
<br />
1. 在 app.js 文件中写代码 运行 npm init -y 先初始化一个 package.json 文件
<br />
2. 安装 express 服务 npm i express -S
<br />
3. 开启 gzip 压缩 先安装 npm i compression -S
<br />
app.js 的代码如下
const express = require('express')
// 开启 gzip 压缩
const compression = require('compression')
const app = express()
// 一定要把这一行代码,写到 静态资源托管之前
app.use(compression())
// 托管 静态资源 文件
app.use(express.static('./dist'))
// 开启 web 服务
app.listen(80, () => {
console.log('server running at http://127.0.0.1')
})
<br />
ssl 证书 个人学习免费的证书网站
image
<br />
pm2 管理 服务器上的网站应用 npm i pm2 -g
image