1、
①安装nodejs
②安装pm2 npm i -g pm2
③[下载nginx](nginx: download)
2、
①将打包好的.output包放到nginx目录html文件夹下
②在html下新建ecosystem.config.cjs,填入以下配置
module.exports = {
apps: [{
name: "first-test", // 应用名称,用于 PM2 管理
exec_mode: "cluster", // 集群模式,允许多个实例并行运行
instances: 1, // 启动的实例数量,建议根据 CPU 核心数设置(如 8 核)
port: "9999", // 应用监听的端口号
script: "./.output/server/index.mjs", // 应用的入口文件
args: "start", // 传递给脚本的参数
env: { MODE: "production" }, // 环境变量,设置为生产环境
max_memory_restart: "500M", // 单实例内存超过 500MB 时自动重启
log_date_format: "YYYY-MM-DD HH:mm:ss", // 日志时间格式
out_file: "/var/log/pm2/out.log", // 标准输出日志文件路径
error_file: "/var/log/pm2/error.log", // 错误日志文件路径
merge_logs: true // 合并所有实例的日志
}]
}
③修改conf文件夹下的nginx.conf配置文件的proxy_pass
http {
......(你的其他代码)
server {
#此处指定项目包路径
# location / {
# # root D:/Download/ChromeDownload/nginx/dist;
# index index.html index.htm;
# autoindex on;
# # index index.mjs;
# }
location / {
# 你的nuxt地址
proxy_pass http://127.0.0.1:9999;
}
}
......(你的其他代码)
}
3、
①启动nginx:执行 nginx.exe 或通过命令行 start nginx 浏览器localhost 即可查看是否运行成功
②在html文件夹下执行 pm2 start ecosystem.config.cjs 浏览器localhost:9999可查看网站页面