当前位置:网站首页>pm2 部署 nuxt3.js 项目
pm2 部署 nuxt3.js 项目
2022-06-24 07:07:00 【郝艳峰Vip】
前言
众所周知,nuxt3.js是基于vue开发ssr,seo的项目比较好的框架,那么开发完成项目,如何部署nuxt项目也是比较重要的,接下来就记录一下我在开发中是如何部署的。
我之前写过一篇vue 和 ssr+nuxt.js 配置环境变量以及pm2进行服务部署,这两篇博客一定要结合起来看。。。
这篇文章只是对配置环境变量做了详细介绍,但是如何部署一带而过,是因为那个时候没怎么研究pm2,正好现在得空,研究成功并上线,本篇文章就详细介绍如何部署。
第一步:打包项目部署到服务器
npm run build:prod
将打包后的文件提交到服务器就好了
我们公司内都是采用jekins将项目自动化打包部署,代码提交后自动执行命令,就可以了。
第二步:服务器上安装pm2
切记一定要全局安装,这样的话服务器上任意开一个命令窗口都可以使用,我就是一开始没有全局安装,导致使用pm2时找不到命令
npm install pm2 -g
第三步:启动服务
pm2 start ecosystem.config.js
//然后使用下边的命令看一下启动的服务列表
pm2 list
如果服务是online说明启动成功,这时候再浏览器看一下自己项目,可以正常访问。
这里解释一个小疑惑:我在上一篇文章中写的启动命令是
pm2 start --env uat,但是在这片中文章中写的又是这个命令,其实这俩是一样的,因为我之前打包的时候已经区分了环境,所以这个时候直接启服务就好了
第四步:设置自动重启
这一步的意义就在于当服务器故障或者重启的时候,pm2服务能自动重启,就不需要每次服务器挂了还要人为敲命令去重启pm2服务。
pm2 startup 设置服务器重启后自动启动服务 linux 服务器可以直接执行 ,而windows服务器就需要安装下边的插件才可以
- 1, 保存启动的服务列表状态
// 这一步是必不可少的
pm2 save
- 2, 全局安装 pm2-windows-startup
cnpm install pm2-windows-startup -g
- 3,设置 pm2-startup
pm2-startup install
以上步骤设置成功后,重启一下服务器,然后打开命令行,输入
pm2 list看一下服务状态,
然后在看一下网站是否能正常访问,能正常访问就说明设置成功。
结束语
到此,pm2部署nuxt项目就成功了,接下来记一下常用到的pm2命令。
| 命令 | 用途 |
|---|---|
| pm2 list | 查看启动的服务列表 |
| pm2 restart nuxtjsDemo | 重启名为nuxtjsDemo的服务 |
| pm2 stop nuxtjsDemo | 终止名为nuxtjsDemo的服务 |
| pm2 delete nuxtjsDemo | 删除名为nuxtjsDemo的服务 |
| pm2 kill | 杀掉服务 |
| pm2 logs nuxtjsDemo | 查看名为nuxtjsDemo的服务日志 |
边栏推荐
- Using sonar for code checking
- 疫情、失业,2022,我们高喊着摆烂和躺平!
- 微博撰写-流程图-序列图-甘特图-mermaid流程图-效果不错
- xtrabackup做数据备份
- [force deduction 10 days SQL introduction] Day3
- Database to query the quantity of books lent in this month. If it is higher than 10, it will display "more than 10 books lent in this month". Otherwise, it will display "less than 10 books lent in thi
- What is graph neural network? Figure what is the use of neural networks?
- 【量化投资】离散傅里叶变换求数组周期
- Solution: Nan occurs in loss during model training
- 一文讲透,商业智能BI未来发展趋势如何
猜你喜欢

数据中台:中台架构及概述

疫情、失业,2022,我们高喊着摆烂和躺平!

【NOI模拟赛】给国与时光鸡(构造)

Why can ping fail while traceroute can

rpiplay实现树莓派AirPlay投屏器

It is enough to read this article about ETL. Three minutes will let you understand what ETL is

Distributed | how to make "secret calls" with dble
![Jenkins is deployed automatically and cannot connect to the dependent service [solved]](/img/fe/f294955a9bdf7492aab360e44e052d.png)
Jenkins is deployed automatically and cannot connect to the dependent service [solved]

Wan Weiwei, a researcher from Osaka University, Japan, introduced the rapid integration method and application of robot based on WRS system

ZUCC_ Principles of compiling language and compilation_ Experiment 0607 grammar analysis ll analysis
随机推荐
rpiplay实现树莓派AirPlay投屏器
【NOI模拟赛】寄(树形DP)
Distributed | how to make "secret calls" with dble
【LeetCode】415. 字符串相加
2022春招面试总结
[life thinking] planning and self-discipline
xtrabackup做数据备份
Get screen width and height tool class
偶然间得到的framework工具类 自用
Win11 blank when using VIM to view content in cmder
Ordering of MySQL composite index
【PyTorch基础教程30】DSSM双塔模型代码解析
用VNC Viewer的方式远程连接无需显示屏的树莓派
Xiaohei ai4code code baseline nibble 1
Matlab camera calibrator camera calibration
Why do you want to file? What are the advantages and disadvantages of website filing?
IDEA另起一行快捷键
疫情、失业,2022,我们高喊着摆烂和躺平!
数据中台:数据治理概述
QT source code analysis -- QObject (2)